|
| 1 | +# Ask for the user's name, if they are called "Bob", print "Welcome Bob!" |
| 2 | +user_name = str(input("What is your name? ")) |
| 3 | +if user_name == "Bob": |
| 4 | + print("Welcome Bob!") |
| 5 | + |
| 6 | +# Ask for the user's name, if they are not called "Alice", print "You're not Alice!" |
| 7 | +user_name = str(input("What is your name? ")) |
| 8 | +if user_name != "Alice": |
| 9 | + print("You're not Alice!") |
| 10 | + |
| 11 | +# Ask the user for a password, if they enter the password "qwerty123", print "You have successfully logged in". If they get it wrong, print "Password failure" |
| 12 | +password = input("Enter your password: ") |
| 13 | +if password == "qwerty123": |
| 14 | + print("You have successfully logged in") |
| 15 | +else: |
| 16 | + print("Password failure") |
| 17 | + |
| 18 | +# Ask the user to enter a number, if the number is even, print "Even", otherwise print "Odd" |
| 19 | +number = int(input("Enter a number: ")) |
| 20 | +if number % 2 ==0: |
| 21 | + print("This is an even number") |
| 22 | +else: |
| 23 | + print("This is an odd number") |
| 24 | + |
| 25 | +# Ask the user for 2 different numbers, if the total of the two numbers is over 21, print "Bust" otherwise print "Safe" |
| 26 | +number_1 = int(input("What is your first number? ")) |
| 27 | +number_2 = int(input("What is your second number? ")) |
| 28 | + |
| 29 | +if number_1 + number_2 > 21: |
| 30 | + print("Safe") |
| 31 | +else: |
| 32 | + print("Bust") |
| 33 | + |
| 34 | +# Ask the user to enter the length and width of a shape and check if it is a square or not |
| 35 | +length = int(input("Enter length of shape: ")) |
| 36 | +width = int(input("Enter width of shape: ")) |
| 37 | + |
| 38 | +if length == width: |
| 39 | + print("This shape is a square") |
| 40 | +else: |
| 41 | + print("This shape is not a square") |
| 42 | + |
| 43 | +# You have had a great year and are going to offer a bonus of 10% to any employee who has a service of over 3 years. Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one. |
| 44 | +current_salary = int(input("What is your current salary? ")) |
| 45 | +years_of_service = int(input("How many years of service have you had? ")) |
| 46 | + |
| 47 | +if years_of_service > 3: |
| 48 | + bonus = current_salary*0.1 |
| 49 | + print("You will be getting " + str(bonus) + " pounds of bonus") |
| 50 | +else: |
| 51 | + print("Sorry you won't be getting a bonus") |
| 52 | + |
| 53 | +# Take a whole number input, if it's positive, print out the number cubed, if it is a negative, print out half its value. |
| 54 | +number = float(input("Enter your number ") |
| 55 | +if number >=0: |
| 56 | + print(number**3) |
| 57 | +else: |
| 58 | + print(number/2) |
| 59 | + |
| 60 | +# Ask for the user's name, if they are called "Alice" print "Hello, Alice", if they are called "Bob", print "You're not Bob! I'm Bob", else print "You must be Charlie" |
| 61 | +username = str(input("What is your name: ")) |
| 62 | +if username == "Alice": |
| 63 | + print ("Hello, Alice") |
| 64 | +elif username == "Bob": |
| 65 | + print("You're not Bob! I'm Bob") |
| 66 | +else: |
| 67 | + print("You must be Charlie") |
| 68 | + |
| 69 | +# Ask the user to enter their age |
| 70 | +# If they are younger than 11, print "You're too young to go to this school" |
| 71 | +# If they are between 11 and 16, print "You can can come to this school" |
| 72 | +# If they are over 16, print 'You're too old for school" |
| 73 | +# If they are 0, print "You're not born yet!" |
| 74 | + |
| 75 | +# age = int(input("Enter your age ")) |
| 76 | +if age < 11: |
| 77 | + print("You're too young to go to this school") |
| 78 | +elif age >= 11 and age <= 16: |
| 79 | + print("You can can come to this school") |
| 80 | +elif age > 16: |
| 81 | + print("You're too old for school") |
| 82 | +elif age == 0: |
| 83 | + print("You're not born yet") |
| 84 | +# |
| 85 | +# Ask the user to enter the name of a month. If the user enters March/April/May: print " is in Spring", otherwise print "I don't know" |
| 86 | +# Expand for the rest of the year, given that summer is June/July/August. Autumn is September/October/November. Winter is December/January/February |
| 87 | +# Ensure that when an unknown month is given it prints "I don't know" |
| 88 | + |
| 89 | +month = str(input("Enter name of month ") |
| 90 | +if month == "March" or month == "April" or month == "May": |
| 91 | + print(month + "is in Spring") |
| 92 | +elif month == "June" or month == "July" or month == "August": |
| 93 | + print(month + " is in Summer") |
| 94 | +elif month == "September" or month == "October" or month == "November": |
| 95 | + print(month + " is in Autumn") |
| 96 | +elif month == "December" or month == "January" or month == "February": |
| 97 | + print(month + " is in Winter") |
| 98 | +else: |
| 99 | + print("I don't know") |
| 100 | + |
| 101 | +# Ask the user for two different numbers, if both numbers are even, print "Even", if both numbers are odd, print "Odd", else print the product of the two numbers |
| 102 | + |
| 103 | +number_1 = int(input("Enter a number: ")) |
| 104 | +number_2 = int(input("Enter a number: ")) |
| 105 | +if number_1 % 2 == 0 and number_2 % 2 == 0: |
| 106 | + print("This is an even number") |
| 107 | +elif number_1 % 2 == 1 and number_2 % 2 == 1: |
| 108 | + print("This is an odd number") |
| 109 | +else: |
| 110 | + print(number_1*number_2) |
| 111 | + |
| 112 | +# Ask the user to input two numbers. Decide which is the number of highest value and print this out |
| 113 | +number_1 = int(input("Enter a number: ")) |
| 114 | +number_2 = int(input("Enter a number: ")) |
| 115 | + |
| 116 | +if number1 > number2: |
| 117 | + print(str(number1) + " has the highest value") |
| 118 | +else: |
| 119 | + print(str(number2) + " has the highest value") |
| 120 | + |
| 121 | + |
| 122 | +# You have had a fantastic year and are now going to offer a bonus of 20% to any employee who has a service of over 7 years, a bonus of 15% to any employee who has a service of over 5 years and a bonus of 10% to any employee who has a service of 3 - 5 years. Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one |
| 123 | + |
| 124 | +current_salary = int(input("What is your current salary? ")) |
| 125 | +years_of_service = int(input("How many years of service have you had? ")) |
| 126 | + |
| 127 | +if years_of_service > 7: |
| 128 | + print("You will be getting " + str(current_salary*0.20) + " pounds of bonus") |
| 129 | +elif years_of_service > 5: |
| 130 | + print("You will be getting " + str(current_salary*0.15) + " pounds of bonus") |
| 131 | +elif years_of_service >=3 and years_of_service <=5: |
| 132 | + print("You will be getting " + str(current_salary*0.10) + " pounds of bonus") |
| 133 | +else: |
| 134 | + print("You get no bonus") |
| 135 | + |
| 136 | +# Take the age and name of three people and determine who is the oldest and youngest and print out the name and age of the oldest and youngest. If all three ages are the same, print that |
| 137 | +name1 = input("What is your name? ") |
| 138 | +age1 = int(input("How old are you? ")) |
| 139 | +name2 = input("What is your name? ") |
| 140 | +age2 = int(input("How old are you? ")) |
| 141 | +name3 = input("What is your name? ") |
| 142 | +age3 = int(input("How old are you? ")) |
| 143 | + |
| 144 | +# #Oldest |
| 145 | +if age1 > age2 and age1 > age3: |
| 146 | + print(name1 + "is the oldest and is " + str(age1) + "years old.") |
| 147 | +elif age2 > age1 and age2 > age3: |
| 148 | + print(name2 + "is the oldest and is " + str(age2) + "years old.") |
| 149 | +elif age3 > age1 and age3> age2: |
| 150 | + print(name3 + "is the oldest and is " + str(age3) + "years old.") |
| 151 | +else: |
| 152 | + ("You are all the same age") |
| 153 | + |
| 154 | +# #Youngest |
| 155 | +if age1 < age2 and age1 < age3: |
| 156 | + print(name1 + "is the youngest and is " + str(age1) + "years old.") |
| 157 | +elif age2 < age1 and age2 < age3: |
| 158 | + print(name2 + "is the youngest and is " + str(age2) + "years old.") |
| 159 | +elif age3 < age1 and age3 < age2: |
| 160 | + print(name3 + "is the youngest and is " + str(age3) + "years old.") |
| 161 | +else: |
| 162 | + ("You are all the same age") |
| 163 | + |
| 164 | +# A school has following rules for their grading system: a. Above 80 – A b.60 to 80 – B c. 50 to 60 – C d. 45 to 50 – D e. 25 to 45 – E f. Below 25 - F Ask user to enter the lesson and the marks for three lessons and print out the corresponding grades for the lesson. |
| 165 | + |
| 166 | +lesson1 = input("Input your lesson:\n") |
| 167 | +mark1 = int(input("Input your mark:\n")) |
| 168 | +lesson2 = input("Input your lesson:\n") |
| 169 | +mark2 = int(input("Input your mark:\n")) |
| 170 | +lesson3 = input("Input your lesson:\n") |
| 171 | +mark3 = int(input("Input your mark:\n")) |
| 172 | + |
| 173 | +print("REPORT CARD:") |
| 174 | + |
| 175 | +#Lesson 1 |
| 176 | +if mark1 > 80: |
| 177 | + print(lesson1 + " - A grade") |
| 178 | +elif mark1 <= 80 and mark1 > 60: |
| 179 | + print(lesson1 + " - B grade") |
| 180 | +elif mark1 <= 60 and mark1 > 50: |
| 181 | + print(lesson1 + " - C grade") |
| 182 | +elif mark1 <= 50 and mark1 > 45: |
| 183 | + print(lesson1 + " - D grade") |
| 184 | +elif mark1 <= 45 and mark1 > 25: |
| 185 | + print(lesson1 + " - E grade") |
| 186 | +elif mark1 < 25: |
| 187 | + print(lesson1 + " - F grade") |
| 188 | +else: |
| 189 | + print("Go to see your teacher") |
| 190 | + |
| 191 | +#Lesson 2 |
| 192 | +if mark2 > 80: |
| 193 | + print(lesson2 + " - A grade") |
| 194 | +elif mark2 <= 80 and mark2 > 60: |
| 195 | + print(lesson2 + " - B grade") |
| 196 | +elif mark2 <= 60 and mark2 > 50: |
| 197 | + print(lesson2 + " - C grade") |
| 198 | +elif mark2 <= 50 and mark2 > 45: |
| 199 | + print(lesson2 + " - D grade") |
| 200 | +elif mark2 <= 45 and mark2 > 25: |
| 201 | + print(lesson2 + " - E grade") |
| 202 | +elif mark2 < 25: |
| 203 | + print(lesson2 + " - F grade") |
| 204 | +else: |
| 205 | + print("Go to see your teacher") |
| 206 | + |
| 207 | +#Lesson 3 |
| 208 | +if mark3 > 80: |
| 209 | + print(lesson3 + " - A grade") |
| 210 | +elif mark3 <= 80 and mark3 > 60: |
| 211 | + print(lesson3 + " - B grade") |
| 212 | +elif mark3 <= 60 and mark3 > 50: |
| 213 | + print(lesson3 + " - C grade") |
| 214 | +elif mark3 <= 50 and mark3 > 45: |
| 215 | + print(lesson3 + " - D grade") |
| 216 | +elif mark3 <= 45 and mark3 > 25: |
| 217 | + print(lesson3 + " - E grade") |
| 218 | +elif mark3 < 25: |
| 219 | + print(lesson3 + " - F grade") |
| 220 | +else: |
| 221 | + print("Go to see your teacher") |
| 222 | + |
0 commit comments