Skip to content

Instantly share code, notes, and snippets.

View yosefsadek's full-sized avatar
🎯
Focusing

Youssef Alsherif yosefsadek

🎯
Focusing
View GitHub Profile
import re
password = input("Enter an email address: ")
while len(password)==0:
password = input("Enter an email address: ")
pattern = "^[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$"
passwordMatch = re.match(pattern, password)
if passwordMatch:
print("VALID")
else:
hours = int(input("Enter the number of hours worked: "))
bears = int(input("Enter the number of toy made: "))
hourswage = hours * 7
bearswage = bears * 0.45
total = hourswage + bearswage
print("Your total wage is: £{:.2f}".format(total))
print ('eserve a souvenir of the train')
#asks the user to input the number of adults and stores it in the adults variable
adults = input("Enter the number of adults: ")
#asks the user to input the number of children and stores it in the children variable
children = input("Enter the number of children: ")
#works out the adult cost by multiplying the number of adults by £5 and storing it in adult total
adulttotal = int(adults) * 5
#works out the child cost by multiplying the number of children by £3 and storing it in child total
childtotal = int(children) * 3
#works out the grand total by adding the adult total to the child total
#function that converts miles to kilometres
def mtokm(value):
answer = value * 1.6
return answer
#function that converts kilometres to miles
def kmtom(value):
answer = value * 0.62
return answer
#function that converts cm to inches
def cmtoinch(value):
def calculate(price):
vat = price * 0.2
return vat
amount = float(input("Enter a price: "))
print("The VAT is £{:.2f}".format(calculate(amount)))
file=open("timetable.csv","r") #opens the file
day = input(" enter day:") #gets the input from the user
found=False #stores whether the day is found in the file, set to False at the beginning
for line in file: #reads each line in the file
timetable=line.split(",") #splits the line into the timetable list
if day == timetable[0]: #checks if the day entered is in element 0 of the list
#if it is it prints the timetable referring to the different elements of the list
print("On " + timetable[0] + " your lessons are: \n"+
"Period 1 - " + timetable[1] + "\n Period 2 - " +
timetable[2] + "\n Period 3 - " + timetable[3] +
total = 0
another = "Y"
#the loop will repeat while the user types Y when asked if they want to enter another number
while another == "Y":
#asks the user to enter a number
number = int(input("Enter a number to add to the total: "))
#adds the number entered to the total
total = total + number
#asks the user if they want to enter another number
another = input("Do you want to enter another number? Y/N ")
answer = 15
attempts= 0
userentry=""
#a loop that repeats while the users guess is not the same as the answer
while answer != userentry:
userentry = int(input("Enter a number between 1 and 20 "))
#each time through the loop 1 is added to the number of attempts
attempts=attempts+1
#after the loop it will say how many attempts it took
print("Well done you correctly guessed the number it took you " + str(attempts) + " attempts")
timestable = input("Enter the timestable you wish to learn (1-12) ")
# loop that will repeat 13 times (0-12)
for x in range(0,13):
# the answer uses x which increases each time to work out the answer
answer = x * int(timestable)
# x is used in the print command to display what it is multiplying the number entered by
print(timestable + " x " + str(x) + " = " + str(answer))
timestable = input("Enter the timestable you wish to learn (1-12) ")
# loop that will repeat 13 times (0-12)
for x in range(0,13):
# the answer uses x which increases each time to work out the answer
answer = x * int(timestable)
# x is used in the print command to display what it is multiplying the number entered by
print(timestable + " x " + str(x) + " = " + str(answer))