guess_number = 7
guess = int(input("guess your number: "))
if guess == guess_number:
print("you won!")
#if the input value is 8 or 6 then print "you were close" ,
# how do i get them in one line, i am having to write 2 lines
# for the same logic, there should be a way to get line 8 and line 10 in one line, that should be line 8
elif guess == 8:
print("oh you were close")
elif guess == 6:
print("oh you were close")
else:
print("uh oh! you lose")
-
how to combine 6 and 8 together in 1 line
-
Greetings, @Jayanta-Prasad
I think this might be what you're looking for...
guess_number = 7 guess = int(input("Guess a number: ")) if guess == guess_number: print("You Won!") elif guess == 8 or guess == 6: print("So close!") else: print("You lose!")
Here I use a "Logical OR" to clean up the
elif
condition. This allows you to specify a condition that isthis OR that
meaning the statement is true if ANY condition is valid.
There is also a "Logical AND" which specifies a condition that is
this AND that
meaning that the statement is true only if ALL conditions are valid.
I hope that helps.
Daniel
ITProTV
Show Host