In: Computer Science
i need the pseudocode and python program for the following problem.
Besides the user entering the number of books purchased this order, they are asked for the number of
points earned for the year before this order and the number of books ordered this year before this order.
There are bonus points awarded based on the number of books previously ordered and number ordered
now. These points should be added to the variable points:
Current order: 0 Previous Orders > 10 Add 1 to point total
Current order: 1, 2, or 3 Previous Orders > 10 Add 2 to point total
Current order: > 3 Previous Orders > 10 Add 5 to point total
// main module
Module main()
// Local variables
Declare Integer points
Declare Integer yearlyBooks
Declare Integer books
// Get numbers
Call getYearlyPoints(points)
Call getYearlyBooks(yearlyBooks)
Call getBooksPurchased(books)
// Display points earned
If books == 0
Display "0 points earned this order"
// Bonus check here
Display “Total points for the year”, points
Else If books == 1
Display "5 points earned this order"
Set points = points + 5
// Bonus check here
Display “Total points for the year”, points
Else If books == 2
Display "15 points earned this order"
Set points = points + 15
// Bonus check here
Display “Total points for the year”, points
Else If books == 3
Display "30 points earned this order"
Set points = points + 30
// Bonus check here
Display “Total points for the year”, points
Else
Display "60 points earned this order"
Set points = points + 60
// Bonus check here
Display “Total points for the year”, points
End If
End Module
// The getYearlyPoints module gets number of books purchased
// this year before this month
// and stores it in the number reference variable.
Module getYearlyPoints (Integer Ref number)
Display "How many points have you earned so far this year?"
Input number
End Module
// The getYearlyBooks module gets number of books purchased
// this year before this month
// and stores it in the number reference variable.
Module getYearlyBooks (Integer Ref number)
Display "How many books did you buy this year before this month?"
Input number
End Module
// The getBooksPurchased module gets number of books purchased
// this month
// and stores it in the number reference variable.
Module getBooksPurchased (Integer Ref number)
Display "How many books did you buy this month?"
Input number
End Module
NOTE: Using the variable name number in all three modules is perfectly legal
because they are each “local” to the module. In the first module the value of
number is returned to the variable points. In the second module it is returned to
the variable yearlyBooks. In the third it is returned to books.
*****This requires some effort so please drop a like if you are satisfied with the solution*****
pseudocode:
define a function getYearlyPoints
print "How many points have you earned so far this year? "
define a function getYearlyBooks
print "How many books did you buy this year before this month? "
define a function getBooksPurchased
print "How many books did you buy this month? "
define main function
Python code:
def getYearlyPoints(): print("How many points have you earned so far this year? ") number = int(input()) return number def getYearlyBooks(): print("How many books did you buy this year before this month? ") number = int(input()) return number def getBooksPurchased(): print("How many books did you buy this month? ") number = int(input()) return number def main(): points = 0 yearlyBooks = 0 books = 0 points = getYearlyPoints() yearlyBooks = getYearlyBooks() books = getBooksPurchased() if (books == 0): print("0 points earned this order\n") if (yearlyBooks > 10): points += 1 print("Total points for the year", points) elif (books == 1): print("5 points earned this order\n") points += 5 if (yearlyBooks > 10): points += 2 print("Total points for the year", points) elif (books == 2): print("15 points earned this order\n") points += 15 if (yearlyBooks > 10): points += 2 print("Total points for the year", points) elif (books == 3): print("30 points earned this order\n") points += 30 if (yearlyBooks > 10): points += 2 print("Total points for the year", points) else: print("60 points earned for this order\n") points += 60 if (yearlyBooks > 10): points += 5 print("Total points for the year", points) if __name__ == "__main__": main()