Ask coding questions

← Back to all posts
help plz
Icekit (62)

I need help with if satements.

Answered by BlueComet (121) [earned 5 cycles]
View Answer
Commentshotnewtop
BlueComet (121)
inp = input("do you want to buy this (yes/no)")
# making a variable
if inp == 'yes':
# checking there input 
    print("you have $5")
if inp == 'no':
# checking  there input
    print("you have $10")
 Hope this  helped you out!
Icekit (62)

Thanks for the help my brother is not as a good of a coder as I am but I figured out how to help him thanks to [email protected]

ChezCoder (1500)

this is the basic structure of an if loop:

if CONDITION:
    # some code...

Example:

if 1 == 1: # if 1 is equal to 1
    print("1 is equal to 1!") # print this.
Icekit (62)

not a loop. i need it so when the things says "do you buy this item" and someone puts yes it says that you now have $5. and if not then it says you did not buy the [email protected]

ChezCoder (1500)

@Icekit yes, you would use an if loop:

if item = "yes":
    print("You now have $5")
else:
    print("You didn't buy the item")
sylashur (50)

@Icekit What issues are you having?

Icekit (62)

@sylashur i need it so when the things says "do you buy this item" and someone puts yes it says that you now have $5. and if not then it says you did not buy the item.

sylashur (50)

@Icekit That would be a comparison between those two values, what else do you need to do?

Icekit (62)

I just don't know how to do that. @sylashur

sylashur (50)

@Icekit What don't you understand about the document that I linked?

chineseperson (0)

Hopefully this is helpful.

chineseperson (0)

if money =="yes":
print("You now have $5")
else:
print("You didn't buy the item!")