47.4k views
0 votes
Write a script which: Uses the input function to get any number and store it in a variable named my_number Create a new variable named calculation which equals my_number plus 9 Multiply calculation by 2 Subtract 4 from calculation Divide calculation by 2 Subtract my_number from calculation Print calculation

User Avagut
by
6.1k points

1 Answer

6 votes

Answer:

# Using the input function

# Prompt the user to input some number

# Convert the input to a float - this will cater for both floating

# numbers and integers

# Store the result in a variable called my_number

my_number = float(input('Please enter some number '))

#Create a variable named calculation which equals my_number plus 9

calculation = my_number + 9

#Multiply calculation by 2

calculation *= 2

#Subtract 4 from calculation

calculation -= 4

#Divide calculation by 2

calculation /= 2

#Subtract my_number from calculation

calculation -= my_number

#Print calculation

print('calculation = ' + str(calculation))

Sample Output

>> Please enter some number 8

calculation = 7.0

Step-by-step explanation:

The above program has been written in Python and it contains comments explaining each line of the code. Please go through the comments. A sample output has also been provided.

User Eusthace
by
5.6k points