In: Computer Science
Python
#Note: use print() to add spaces between items and when needed
in the receipt
#(e.g. between user entries and between the entries and the
receipt)
#1 Ask the user for a number using the prompt: NUMBER?
# Convert the user entered number to an integer
# Calculate the square of the number and display the result on
screen with the following text before it: Your number squared
is
#2 Ask the user for a first number using the prompt: first
number?
# Ask the user for a second number using the prompt: second
number?
# Convert the two numbers to integers
# Multiply the first number by the second number and display the
result on screen with the following text before it: Result:
"""
#3 Develop a simple food receipt
a. Ask the user for inputs about two food items using the following
prompts in turn. Do not forget to assign each user
entry to a unique variable name:
Item1 name?
Item1 price?
Item1 quantity?
Item2 name?
Item2 price?
Item2 quantity?
b. Convert the price and quantity variables to integers
c. Calculate the total cost for the order by calculating each
item's total price by
multiplying price and quantity for each item and then adding up the
total prices for the two items
d. Display the results using the format:
RECEIPT
You ordered: [item1 name] and [item2 name]
Total cost: $ [total price for both items calculated in 3c
above]
"""
#Start your code below
"""
Enhance your simple food receipt
a. Ask the user for inputs about two food items using the following
prompts in turn. Do not forget to assign each user
entry to a unique variable name:
First item name?
First item price?
First item quantity?
Second item name?
Second item price?
Second item quantity?
Third item name?
Third item price?
Third item quantity?
b. Convert the price and quantity variables to integers
c. Calculate the total cost for the order by calculating each
item's total price by
multiplying price and quantity for each item and then adding up the
total prices for the three items
d. Calculate the total cost plus tax for the order by multiplying
the total cose calculated in c by the tax rate of .09
then adding the tax to the total cost
e. Display the results using the format:
RECEIPT
You ordered: [First item name] [Second item name] [third item
name]
Total cost: $ [total price for all items calculated in 3c
above]
Total cost plus tax: $ {total cost plus tax calculated in 3d
above}
"""
#Start your code below
Code 1 Python 3
============================================================================================
#input from user
num=input('NUMBER? ')
# Convert the user entered number to an integer
num=int(num)
# Calculate the square of the number and display the result on
screen with the following text
num=num*num
print('Your number squared is: ',num)
============================================================================================
Output
============================================================================================
Code 2
# Ask the user for a first number using the prompt
num1=input('first number? ')
# Ask the user for a second number using the prompt:
num2=input('second number? ')
# Convert the two numbers to integers
num1=int(num1)
num2=int(num2)
# Multiply the first number by the second number and display the
result on screen with the following text before it:
res=num1*num2
print('Result: ',res)
============================================================================================
Output
============================================================================================