1. Simple input/output interaction.
Print (' information interaction ') name=input (' Please enter name ')Print ('hi,%s. '%name)
2. The user enters two numbers, calculates and outputs the sum of two digits: (try to do this with just one line of code)
1A=input ('Please enter the first number:')2B=input ('Please enter a second number:')3 #Enter a number4C=int (a) +Int (b)5 #sum6 Print('The sum of the two numbers is:%.2f'%c)7 #Output Results
One line of code implementation
Print (' two sum of%.2f'% (float (input (' Enter first number:') ') +float ( Input (' Please enter a second number:')))
3. Enter a radius to calculate the area of the circle.
m=3.14159# set pi r=input (' Please enter radius of circle:')# input radius s=float (M) *float (R) *float (r)# formula calculates print( The area of the circle is:%. 2f'%s)# Output Results
Python Basics Exercises