CIS 111 Input, output

Objectives

  • Get user input
  • Convert string input into numbers
  • Display values

Getting user input

Note in the following examples that the input function will get a string from the user. The int() and float() functions are used to turn that string into an integer or a floating-point number. The input function takes an optional prompt one of its parameters.

  • Example of getting user input: x = input()
  • Example of getting a string from the user using a prompt: name = input("Enter your name: ")
  • Example of getting an integer from the user: age = int(input("Enter your age: "))
  • Example of getting a float from the user: rate = float(input("Enter the rate: "))

Displaying values

  • Example of displaying a value: print("Hello")
  • Example of displaying multiple values: print("Your age is", age)
  • Note that multiple values will be separated by spaces using this technique.