MUST BE POSTED IN PYTHON ) Write a program to ask a user to enter their grade in
ID: 3572990 • Letter: M
Question
MUST BE POSTED IN PYTHON ) Write a program to ask a user to enter their grade in a course (out of 100) and then tell him if he passed or failed the course. Call the program pass.py 2) Write a program to ask a user to enter their grade in a course (out of 100) and then tell him his letter grade, given that: Grade >= 85 is an A Grade >= 70 is a B Grade >= 60 is a C Grade >= 50 is a D Grade < 50 is a F Call the program grade.py 3) A shop is having a special offer to give a discount of 10% if the customer buys items totaling $100 or more, and a discount of 5% if the customer buys items totaling $50 up to $100, and no discount if the total is less than $50. Write a program to ask the user for the total of the items, and then display how much is to paid after the discount (if any). Call your program discount.py
Explanation / Answer
Question 1:
pass.py
Note: taken 50 as a pass mark here.
def main():
grade = int(input("Enter a grade :"))
if grade > 50:
print "he passed the course"
else:
print "he failed the course"
main();
Output:
sh-4.3$ python main.py
Enter a grade :67
he passed the course
sh-4.3$ python main.py
Enter a grade :40
he failed the course
Question 2:
grade.py
def main():
grade = int(input("Enter a grade :"))
if grade >= 85:
letterGrade = 'A'
elif grade >=70 and grade < 85:
letterGrade = 'B'
elif grade >=60 and grade < 70:
letterGrade = 'C'
elif grade >=50 and grade < 60:
letterGrade = 'D'
else:
letterGrade = 'F'
print "Letter grade is ", letterGrade
main();
Question 3:
discount.py
def main():
total = int(input("Enter the total of the items :"))
if total >= 100:
discount = 10
elif total >=50 and total < 100:
discount = 5
else:
discount = 0
discontAmount = (total * discount)/100.0
print "Discount is ", discontAmount
finalAmount = total - discontAmount
print "Final amount to be paid", finalAmount
main();
Output:
sh-4.3$ python main.py
Enter the total of the items :75
Discount is 3.75
Final amount to be paid 71.25
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.