Jump to content

Python Question

Go to solution Solved by vanished,

you are missing a ) in the previous line I believe

OK so im doing what I thought was a simple assignment for one of my classes, but I cant figure out why this isn't working... 

 

It's telling me my syntax is wrong on "total = won + lost"  when I don't think it is?? I'm using python 3 if that matters.  

 

What exactly am I doing wrong here? 
 

Spoiler

# ask the user for their favorite baseball team name using an input statement
team = input("What is the name of your favorite baseball team? :")
# ask the user for the numbers of games won using eval input
won = eval(input("How many games did they win? :"))
# ask the user for the numbers of games lost using eval input
lost = eval(input("How many games did they lose? :")
# calculate the percentage of games won (figure this out on your own)
total = won + lost
games_won = won / total * 100
# print an output statement similar to the sample run
print(team, "won", games_won, "% of their games")

 

"If a Lobster is a fish because it moves by jumping, then a kangaroo is a bird" - Admiral Paulo de Castro Moreira da Silva

"There is nothing more difficult than fixing something that isn't all the way broken yet." - Author Unknown

Spoiler

Intel Core i7-3960X @ 4.6 GHz - Asus P9X79WS/IPMI - 12GB DDR3-1600 quad-channel - EVGA GTX 1080ti SC - Fractal Design Define R5 - 500GB Crucial MX200 - NH-D15 - Logitech G710+ - Mionix Naos 7000 - Sennheiser PC350 w/Topping VX-1

Link to comment
https://linustechtips.com/topic/543924-python-question/
Share on other sites

Link to post
Share on other sites

you are missing a ) in the previous line I believe

Solve your own audio issues  |  First Steps with RPi 3  |  Humidity & Condensation  |  Sleep & Hibernation  |  Overclocking RAM  |  Making Backups  |  Displays  |  4K / 8K / 16K / etc.  |  Do I need 80+ Platinum?

If you can read this you're using the wrong theme.  You can change it at the bottom.

Link to comment
https://linustechtips.com/topic/543924-python-question/#findComment-7196026
Share on other sites

Link to post
Share on other sites

Aren't you missing a ) on the line two lines above "total = won + lost"?

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/543924-python-question/#findComment-7196031
Share on other sites

Link to post
Share on other sites

Just now, Ryan_Vickers said:

you are missing a ) in the previous line I believe

LOL you're right. it works perfectly now. haha

 

This is why I hate programming. Soooo easy to make a stupid mistake like that and be looking for hours.

"If a Lobster is a fish because it moves by jumping, then a kangaroo is a bird" - Admiral Paulo de Castro Moreira da Silva

"There is nothing more difficult than fixing something that isn't all the way broken yet." - Author Unknown

Spoiler

Intel Core i7-3960X @ 4.6 GHz - Asus P9X79WS/IPMI - 12GB DDR3-1600 quad-channel - EVGA GTX 1080ti SC - Fractal Design Define R5 - 500GB Crucial MX200 - NH-D15 - Logitech G710+ - Mionix Naos 7000 - Sennheiser PC350 w/Topping VX-1

Link to comment
https://linustechtips.com/topic/543924-python-question/#findComment-7196048
Share on other sites

Link to post
Share on other sites

2 minutes ago, bcredeur97 said:

LOL you're right. it works perfectly now. haha

 

This is why I hate programming. Soooo easy to make a stupid mistake like that and be looking for hours.

The worst part is that usually when there's a mistake like this, you get a bunch of other unrelated errors instead of it telling you the actual problem :D

Solve your own audio issues  |  First Steps with RPi 3  |  Humidity & Condensation  |  Sleep & Hibernation  |  Overclocking RAM  |  Making Backups  |  Displays  |  4K / 8K / 16K / etc.  |  Do I need 80+ Platinum?

If you can read this you're using the wrong theme.  You can change it at the bottom.

Link to comment
https://linustechtips.com/topic/543924-python-question/#findComment-7196064
Share on other sites

Link to post
Share on other sites

28 minutes ago, bcredeur97 said:

LOL you're right. it works perfectly now. haha

 

This is why I hate programming. Soooo easy to make a stupid mistake like that and be looking for hours.

This is why most programmers have a good editor. Linters catch these kinds of things for you so you don't have to waste your time on simple typos you missed.

 

For example using PyCharm, it puts an indicator at the end of that line with the message ',' or ')' expected

 

7d0ee8cf49.png

Link to comment
https://linustechtips.com/topic/543924-python-question/#findComment-7196326
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×