# Help me with my code!

I am trying to create a simple game. But on the second stage of the game that I programmed, it keeps on saying ‘invalid syntax’.

``````import random

print("Welcome to my game! You have to get the most amount of harvest as you can. But be careful, the weather will depend on if you have a good harvest!")
print("You start with 10 seeds and if you go to the next stage then you have the option to buy more seeds. Each seed costs \$1.")
print("Each seed after harvest sells for \$2")

weather = random.choice(['Sunny','Little cloud','Little cloud','Little cloud','Little cloud','Overcast','Rainy'])
print(weather)

if weather=="Sunny":
print("Your crops died from no water")
elif weather=="Little cloud":
print("Your crops survived! You get \$10. Go to the next stage!")
elif weather=="Overcast":
else:

if weather=="Little Cloud":
seeds1 = int(input("How many seeds do you want to buy?")

if seeds1 == "10":
print("10 seeds left")
elif seeds1 == "9":
print("9 seeds left")
elif seeds1 == "8":
print("8 seeds left")
elif seeds1 == "7":
print("7 seeds left")
elif seeds1 == "6":
print("6 seeds left")
elif seeds1 == "5":
print("5 seeds left")
elif seeds1 == "4":
print("4 seeds left")
elif seeds1 == "3":
print("3 seeds left")
elif seeds1 == "2":
print("2 seeds left")
elif seeds1 == "1":
print("1 seeds left")
else:
print("Game Over")
``````

It always comes up at the ‘if seeds1 == 10:’.
Thanks

Problem1.
`seeds1 = int(input("How many seeds do you want to buy?")` ) (You missed closing parentheses)

problem2.
`if weather=="Little Cloud"`
c of cloud should be lowercased.

Keep testing…
suggestion:
You can use time module (`import time` ) and by using `time.sleep(seconds)` you can introduce little pause while explaining / introducing your game.

Thanks for the help. It was very useful. But I have another problem now, it says that ‘seeds1’ is undefined.

I forgot to mention that…

As you’re taking input from users and converting it into int type.

But in next code block you’re comparing `seeds1` to strings like “1”, “2” and so on!

What should I write instead then?

`seeds1 == 10`
`seeds1 == 9`
`seeds1 == 8`
`seeds1 == 7`
`seeds1 == 4`
`seeds1 == 3` and so on…

`seeds1` is of int data type so you need to compare it with integers not strings like “10”, “9” etc

If I write that won’t it always be ‘Game Over’?

It won’t as order of your conditional statements is in right order!

I have figured out the problem, but know I have another one. I tried to add a ‘money’ variable and then I tried to add money to that, but it always says

Traceback (most recent call last):
File “C:\Users\miara\Documents\Python\simplesims.py”, line 41, in
money=money-“10”
TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’

This is my code:

``````import random
import time

money = "0"

print("Welcome to my game! You have to get the most amount of harvest as you can. But be careful, the weather will depend on if you have a good harvest!")
print("You start with 10 seeds and if you go to the next stage then you have the option to buy more seeds. Each seed costs \$1.")
print("Each seed after harvest sells for \$2")
print("         ")

input("Press the enter key to carry on")

weather = random.choice(['Sunny','Little cloud','Little cloud','Little cloud','Little cloud','Overcast','Rainy'])
print(weather)

print("               ")

if weather=="Sunny":
print("Your crops died from no water")
elif weather=="Little cloud":
print("Your crops survived! You get \$10. Go to the next stage!")
seeds1 = int(input("How many seeds do you want to buy?"))
money="money"+"10"
elif weather=="Overcast":
else:

print("            ")

if weather == "Little cloud":
input("Press the enter key to carry on")
else:
input("Press the enter key to exit.")

print("                ")

if weather=="Little cloud":
if seeds1 == 10:
print("10 seeds bought")
money=money-"10"
elif seeds1 == 9:
print("9 seeds bought")
money=money-"9"
elif seeds1 == 8:
print("8 seeds bought")
money=money-"8"
elif seeds1 == 7:
print("7 seeds bought")
money=money-"7"
elif seeds1 == 6:
print("6 seeds bought")
money=money-"6"
elif seeds1 == 5:
print("5 seeds bought")
money=money-"5"
elif seeds1 == 4:
print("4 seeds bought")
money=money-"4"
elif seeds1 == 3:
print("3 seeds bought")
money=money-"3"
elif seeds1 == 2:
print("2 seeds bought")
money=money-"2"
elif seeds1 == 1:
print("1 seed bought")
money=money-"1"
else:
print("Game Over")

if weather == "Little cloud":
print("The seeds have been planted once again and the same applies with the weather. Please wait 'one year' (1 min)")
time.sleep(60)

print("            ")

weather1 = random.choice(['Sunny','Little cloud','Little cloud','Little cloud','Little cloud','Overcast','Rainy'])
print(weather1)

print("           ")

if weather1=="Sunny":
print("Your crops died from no water")
elif weather1=="Little cloud":
print("Your crops survived! You get \$10. Go to the next stage!")
seeds2 = int(input("How many seeds do you want to buy?"))
elif weather1=="Overcast":
else:

print("            ")

if weather1 == "Little cloud":
input("Press the enter key to carry on")
else:
input("Press the enter key to exit.")

print("                ")

if weather1=="Little cloud":
if seeds2 == 20:
print("20 seeds bought")
elif seeds2 == 19:
print("19 seeds bought")
elif seeds2 == 18:
print("18 seeds bought")
elif seeds2 == 17:
print("17 seeds bought")
elif seeds2 == 16:
print("16 seeds bought")
elif seeds2 == 15:
print("15 seeds bought")
elif seeds2 == 14:
print("14 seeds bought")
elif seeds2 == 13:
print("13 seeds bought")
elif seeds2 == 12:
print("12 seeds bought")
elif seeds2 == 11:
print("11 seeds bought")
elif seeds2 == 10:
print("10 seeds bought")
elif seeds2 == 9:
print("9 seeds bought")
elif seeds2 == 8:
print("8 seeds bought")
elif seeds2 == 7:
print("7 seeds bought")
elif seeds2 == 6:
print("6 seeds bought")
elif seeds2 == 5:
print("5 seeds bought")
elif seeds2 == 4:
print("4 seeds bought")
elif seeds2 == 3:
print("3 seeds bought")
elif seeds2 == 2:
print("2 seeds bought")
elif seeds2 == 1:
print("1 seed bought")
else:
print("Game Over")

``````

I’ve figured out the problem. It’s okay

1 Like

I would suggest you if you are a college going or coaching going student then you can clear your doubts with your teachers.