So I'm doing a homework assignment where we are meant to make a program that asks the user their name, age and what computer they want to buy. Once they say what computer they want to buy it checks whether they can afford it and if they can it stops but if they can't it checks whether they are 18 or over to see if they are eligible for a loan. This is the part of the code that I keep getting an error with:
The specific bit where I get the error message is where it says "if money >= price :". it says invalid syntax and then highlights the colon at the end of that line, I haven't even been able to run the code.
If you're interested in the entirety of my code, here it is:
Also, please no hate. I've only been learning python for about a week and a half and if any of my code is wrong I would like some hints please :) but I don't want anyone to do my work for me, Thank you.
1 2 3 4 5 6 7 8 9 10 |
def moneycheck(): money = int ( input ( "How much money do you have to purchase your computer? $" ) if money > = price : print ( "Congratulations you have enough to buy your dream computer! Please come inside to complete your purchase." ) else : age = int ( input ( "I'm sorry but that is not enough to buy the computer you have chosen, how old are you? " ) if age > = 18 : ( "You are eligible for our loan service, please come inside to discuss the terms for us to loan you a computer." ) else : ( "You are not eligible for our loan service and you don't have enough money for the computer you have chosen. Please save up enough money to buy your computer and come again another day." ) |
If you're interested in the entirety of my code, here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
from time import sleep #This code defines the function that will run a banner def title (): print ( "*******************************" ) print ( "******Jims Computer Store******" ) print ( "*******************************" ) print ("") #Make a list of all the computers with lists of all possible answers to select these computers pclist = [ "Home Basic $900" , "Office $1200" , "Gamer $1500" , "Studio $2200" ] hblist = "home basic" offlist = "office" gmrlist = "gamer" stulist = "studio" #Define a function that prints the list of computers and asks the user which one they would like def pcque (): print ( "Nice to meet you, " + name.title() + ", this is the list of computers we have available today:" ) totalnum = 4 count = 0 while count < totalnum : print (pclist[count]) count = count + 1 sleep( 3 ) pcchoice = input ( "What computer would you like? " ) if pcchoice.lower() = = hblist: print ( "You have chosen the Home Basic computer." ) price = 900 moneycheck() elif pcchoice.lower() = = offlist: print ( "You have chosen the Office computer." ) price = 1200 moneycheck() elif pcchoice.lower() = = gmrlist: print ( "You have chosen the Gamer computer." ) price = 1500 moneycheck() elif pcchoice.lower() = = stulist: print ( "You have chosen the Studio computer." ) price = 2200 moneycheck () else : print ( "You have chosen an invalid answer, please try again." ) pcque () #function for checking if they have enough money to buy the computer def moneycheck(): money = int ( input ( "How much money do you have to purchase your computer? $" ) if money > = price : print ( "Congratulations you have enough to buy your dream computer! Please come inside to complete your purchase." ) else : age = int ( input ( "I'm sorry but that is not enough to buy the computer you have chosen, how old are you? " ) if age > = 18 : ( "You are eligible for our loan service, please come inside to discuss the terms for us to loan you a computer." ) else : ( "You are not eligible for our loan service and you don't have enough money for the computer you have chosen. Please save up enough money to buy your computer and come again another day." ) #Start printing things title () sleep( 1 ) #Ask the user their name and what pc they would like name = input ( "Hi, welcome to Jims computer store, what's your name? " ) sleep( 1 ) pcque () |