Input
So far we have been setting the numbers and string beforehand.In this post,we will will explore how the user can input a number and example of converting temperature Fahrenheit to Celsius with the user input.
##input() for user input,save the user input to the variable somebody
print("Enter your name: ")
somebody = input()
print("Hi", somebody, "how are you today?")
print("Enter your name: ")
somebody = input()
print("Hi", somebody, "how are you today?")
Output
The output below show that the program "pauses" and await the user input
Next,I input my name:eric,the variable somebody will save my input
Converting number with user input
Next,we will be converting temperature Fahrenheit to Celsius with the user input.
print ("This program converts Fahrenheit to Celsius")
print ("Type in a temperature in Fahrenheit: ",)
##save the user input to the variable fahrenheit
fahrenheit = float(input())
##convert the fahrenheit to celsius
celsius = (fahrenheit - 32) * 5.0 / 9
##print out the celsius temperature
print ("That is", celsius,"degrees Celsius")
print ("Type in a temperature in Fahrenheit: ",)
##save the user input to the variable fahrenheit
fahrenheit = float(input())
##convert the fahrenheit to celsius
celsius = (fahrenheit - 32) * 5.0 / 9
##print out the celsius temperature
print ("That is", celsius,"degrees Celsius")
Output
The output below show that the program "pauses" and await the user input
Next,I input my Fahrenheit temperature,the variable Fahrenheit will save my input and print it out
In the next post,we will be touching GUI(Graphic User Interface)






No comments:
Post a Comment