06 - User Input Integer

 1. The term _________ in Python (and generally in mathematics) is referring to a whole number. E.g 100, or 3
Note: The following video from provides examples and a full overview of obtaining integer user input





 2. Analyse the code below and explain why line 4 causes an error.
num1=int(input("Enter number 1:"))
num2=input("Enter number 2:")

  num2 has not been converted to an integer and as a string it cannot be added to

  There is no error

  num2 is an integer and it should be a string

  num2 should be declared as a boolean value

 3. Here, a programmer has attempted to convert the user input for num2 to an integer, but there is an error. What is it?
num2=int(input("Enter number 2:")

  A msising bracket at the end of line 1

  There is nothing missing - this is a mystery

  Speech marks around "num2" in line 2

  A missing colon at the end

 4. There is another way of converting num2 to integer without doing it at the input stage. What is it?
num2=input("Enter number 2:")

  Change line 2 to: Cint(num2)+4

  None of the above

  Change line 2 to: print(int(num2)+4)

  Change line 2 to: convert_to_integer(num2) + 4

 5. In the following code, on what line have the inputs been converted into integers?
def simplecalc():
     #add another variable and ask for a number input for 'z'
     #make the total variable add up the three numbers x+y+z
     x=input("Enter a number:>>")
     y=input("Enter another number:>>")
     print("Adding these numbers will give you",total)

  On Line 8

  On Line 6

  They have not been converted into integers

  On Line 1

 6. In the following program, if you enter the numbers 8 and 6, what will the output be?
def sum():
     print("This is a program that will perform addition")
     num1=input("Enter Number 1:") 
     num2=input("Enter Number 2:") 
     print("Adding the two numbers gives you:",sum)





 7. The following program does not work. What line could you change to fix this and to what?
def pocketmoney():
     print("Keeping track of your pocket money")
     money=int(input("How much money do you have in the piggy bank?:"))
     spent=(input("How much money have you spent?:"))
     print("You have this much money left:",left)

  Line 4 to: int(input("How much money have you spent?:")) = spent

  Line 4 to: spent=int(input("How much money have you spent?:"))

  This is a critical error that cannot be fixed by conversion to integer

  Line 3 to: int(money)input("How much money do you have in the piggy bank?:"))

 8. Can you spot the error?
def division():
     x=input("Enter a number larger than 10:")
     y=input("Enter a number between 1 and 5:")

  y has been converted to an integer but x has not

  Subtraction cannot be performed on integers - real numbers would be necessary

  x is a number larger than 10 which python does not allow

  x has been converted to an integer but y has not

 9. Whole numbers (numbers with no _______________) are called integers

  decimal place

  numerical values above 100 or under 0.5

  numerical values below 10


 10. What is the output for the following program if the inputs are 9 and 9
x=input("Enter value for x:")
y=input("Enter value for y:")



  An error would occur