ELLAK - Python course - ws01

EL/LAK - Python Course

worksheet 01

  1. Write a line of code that will print your name.
  2. How do you enter a comment in a program?
  3. What do the following lines of code output? ALSO: Why do they give a different answer?
    print(2 / 3)
    print(2 // 3)
  4. Write a line of code that creates a variable called pi and sets it to an appropriate value.
  5. Why does this code not work?
    A = 22
    print(a)
  6. All of the variable names below can be used. But which ONE of these is the better variable name to use?
    a
    A
    Area
    AREA
    area
    area_of_rectangle
    Area_Of_Rectangle
  7. Which of these variables names are not allowed in Python? (More than one might be wrong. Also, this question is not asking about improper names, just names that aren't allowed. Test them if you aren't sure.)
    apple
    Apple
    APPLE
    Apple2
    1Apple
    account number
    account_number
    account.number
    accountNumber
    account#
    pi
    PI
    fred
    Fred
    GreatBigVariable
    greatBigVariable
    great_big_variable
    great.big.variable
    2x
    x2x
    total%
    #left
  8. Why does this code not work?
    print(a)
    a = 45
  9. Explain the mistake in this code:
    pi = float(3.14)
  10. This program runs, but the code still could be better. Explain what is wrong with the code.
    radius = float(input("Radius:"))
    x = 3.14
    pi = x
    area = pi * radius ** 2
    print(area)
  11. Explain the mistake in the following code:
    x = 4
    y = 5
    a = ((x) * (y)
    print(a)
  12. Explain the mistake in the following code:
    x = 4
    y = 5
    a = 3(x + y)
    print(a)
  13. Explain the mistake in the following code:
    radius = input(float("Enter the radius:"))
  14. Do all these print the same value? Which one is better to use and why?
    print(2/3+4)
    print(2 / 3 + 4)
    print( 2 / 3+ 4 )
  15. Write a Python program that will use escape codes to print a double-quote and a new line 
  16. Can a Python program print text to the screen using single quotes instead of double quotes?
  17. Why does this code not calculate the average?
    print(3 + 4 + 5 / 3)
  18. What is an ``operator'' in Python?
  19. What does the following program print out?
    x = 3
    x + 1
    print(x)
  20. Correct the following code:
    user_name = input("Enter your name: )"
  21. Correct the following code:
    value = int(input(print("Enter your age")))