Advertisement
earlution

Initial 5 problems

May 20th, 2020
1,708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. # Problem 1
  2. # ver a - concatenation
  3. def problem_one_a():
  4.     name = input("What is your name: ")
  5.     print("Hello " + name) # Note the space character after 'Hello'
  6.  
  7. # ver b - multiple arguments
  8. def problem_one_b():
  9.     name = input("What is your name: ")
  10.     print("Hello", name)  # Note the lack of space character after 'Hello'
  11.  
  12. # Problem 2
  13. def problem_two():
  14.     num_one = int(input("Enter a whole number: "))
  15.     num_two = int(input("Enter another whole number: "))
  16.     print(num_one + num_two)
  17.  
  18. # Problem 3
  19. def problem_three():
  20.     num = int(input("Enter a whole number in the range 1 - 10: "))
  21.     if num > 10:
  22.         print("Number was supposed to be between 1 - 10!")
  23.     elif num >= 6:
  24.         print("The number is within the range 6 - 10")
  25.     else:
  26.         print(("The number is within the range 1 - 5"))
  27.  
  28. # Problem 4
  29. def problem_four():
  30.     age = int(input("Enter your age: "))
  31.     if age > 60:
  32.         print("You are old!")
  33.     elif age >= 40:
  34.         print("You are middle aged.")
  35.     elif age >= 20:
  36.         print("You are young.")
  37.     elif age >= 13:
  38.         print("You are a teenager.")
  39.     else:
  40.         print("You are a child.")
  41.     print()
  42.  
  43. # Problem 5
  44. def problem_five():
  45.     num_1 = int(input("How old are you: "))
  46.     if num_1 < 16 or num_1 >= 65:
  47.         print("Your addmission fee is £5")
  48.     else:
  49.         print("Your addmission fee is £10")
  50.  
  51. # Main program
  52. go_again_choices = ["y", "yes", "yep", "mos def", "whay eye"]
  53. go_again = "yes"
  54.  
  55. while go_again in go_again_choices:  
  56.     valid_choices = ["1a", "1b", "2", "3", "4", "5"]        
  57.     choice = input("Which program do you want to run (1a, 1b, 2, 3, 4, 5): ")
  58.     print()
  59.    
  60.     while choice not in valid_choices:
  61.         print("Not a valid choice!")
  62.         choice = input("Please choose from - 1a, 1b, 2, 3, 4, 5: ")
  63.     if choice == "1a":
  64.         problem_one_a()
  65.         print()
  66.     elif choice == "1b":
  67.         problem_one_b()
  68.         print()
  69.     elif choice == "2":
  70.         problem_two()
  71.         print()
  72.     elif choice == "3":
  73.         problem_three()
  74.         print()
  75.     elif choice == "4":
  76.         problem_four()
  77.     elif choice == "5":
  78.         problem_five()
  79.         print()
  80.     go_again = input("Do you want to go again (y / n): ").lower()
  81.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement