Preview

05 - User Input String

 1. A string is usually a bit of text you want to display to someone, or "export" out of the program you are writing
Note: The following video from www.teachyourselfpython.com goes through some of the basics of user string input

  TRUE

  FALSE

 2. An example of a string would be 'Joe Bloggs'

  FALSE

  TRUE

 3. Python knows you want something to be a string when you put either ________________ around the text.

  ampersand signs (&)

  : colons

  brackets ( )

  " (double-quotes) or ' (single-quotes)

 4. Why might you put ' (single-quotes) around some strings and not others?

  you may use a single-quote inside a string that has double-quotes

  you may do this if you are a java programmer and dislike double quotes

  you may do this purely to avoid any logical errors

  you may do this if you are performing a complex maths calculation and need more space

 5. To ask the user for string input (of their name) you might write something like: name=int(input("Enter your name:"):

  True

  False

 6. On which line is the user being asked to enter a string as input
import time
def verify():
  print("===CHECKING IDENTITY=====")
  time.sleep(1.1)
  print(".....please wait while we do important stuff....")
  time.sleep(1.1)
  print("-----Are you Ready----?")
  password=input("Enter the secret password:")
  if password=="open123":
    print("Access Granted")
  else:
    print("Access Denied")
  verify()
  
verify()

  7

  9

  6

  8

 7. In the following code, how many times is the user being asked to input strings?
def chatbot():
  print("WELCOME TO THE CHATTERBOT")
  name=input("What is your name?")
  print("Nice to meet you "+name)
  food=input("What is your favourite food, if you don't mind me asking:")
  print(food+"...wow....mmm.....I quite like "+food+" too")
  favword=input("Tell me your favourite word and I'll repeat it five times, just because I can!:")
  print(favword+favword+favword+favword+favword)


chatbot()

  2

  3

  4

  1

 8. In the following line, how is the user input being stored?
food=input("What is your favourite food, if you don't mind me asking:")

  It is being stored inside the variable called 'food' once the user inputs it

  It is being stored inside the speech marks which is the input command

  None of the above

  It is being stored inside the'input' text, which calls an input function

 9. Analyse the following program that asks for two lots of user input. What is the output if the user enters 'Rut' and '15'
def username():
  print("====Enter details and we will generate a username for you=====")
  firstname=input("Enter first three letters of first name>>")
  age=input("Enter your age e.g. 15")
  print("Your username is:"+age+firstname)



username()

  Error - age is being entered as a standard string, but should be integer

  51tuR

  15Rut

  Rut15

 10. The following code will be executed and allow the user to input data, but what is wrong?
input("Enter username:")
input("Enter password:")

  The 'input' should be in capitals: INPUT

  As no variables have been used (e.g. username=input("Enter username"), the input will not be stored

  Nothing is wrong - the data will be entered and stored in memory

  There is no need for a semi colon at the end of each statement