Login

Back

Getting data into Python

Q1. Type this code into a new Python program. It doesn't work. Write down the error you got. Explain why it didn't work and then correct the error so it runs properly. Test the code.

Print('What is your name?')
name = input()
print ('Your name is',name)

Q2. Type this code into Python. It doesn't fully work. Write down the error you got. Explain why it didn't work and then correct the error so it runs properly. Test the code.

#Getting data into Python

print('What is your name?')
name = input()
print ('Your name is',name)

print('What is your age?')
age = input()
print ('Your name is',age)

print (age + 4) 

Q3. A better way to get data into your program using input is to combine the question asking for data with the input statement. Type this in. Compare it to your previous program. Does it work?

#Getting data into Python

name = input('What is your name?')
print ('Your name is',name)

age = int(input('What is your age?'))
print ('Your name is',age)

print (age + 4)

Q4. Looking at Q3 above, suppose someone entered their age as 12.5 when they ran the program. What would happen? Why? Change the program so that it runs when someone enters their age using a decimal number.
Q5. When you use the input keyword, what data type is always read in?
Q6. What must you always do to a number that you want to manipulate mathematically, which has been inputted using the input keyword?
Q7. How do you convert a string into an integer?
Q8. How do you convert a string into a floating point number?
Q9. In the line, 

name = input('What is your name?')

the cursor waits immediately after the question mark. This is not easy on the eye! what might you do about it? Suggest two possible courses of action.
Q10.  
The question asking for your age gets displayed immediately after your name is displayed. Suggest two ways to space out what gets displayed. 
Q11. Num1 is an integer that hold 234 and num2 is an integer that holds 567. Write a program that displays 234567.
Q12. Num1 is a float that hold 10.34 and num2 is an float that holds 6.4. Write a program that displays 10.346.4.
Q13. What does concatenation mean?

Back