'Print wont print after elif statment [closed]
So I am trying to make a cowboy game (double 07) in python. I have the first elif statement working just fine but the other two aren't working. There are more to come but I want to sort the errors out so I don't continue doing them.
import sys
import os
import time
import random
import colorama
from colorama import Fore
import random
#cool typing effect
from sys import stdout as s
from time import sleep as j
def w(print):
for i in print:
j(.03)
s.write(i)
s.flush()
next = input()
def noinput(print):
for i in print:
j(.03)
s.write(i)
s.flush()
#main code for the game hub
def guess_the_number():
os.system('clear')
num = random.randint(1, 50)
guess = "none"
while guess != num:
guess = input(Fore.CYAN + "Choose a number: ")
guess = int(guess)
if guess == num:
w(Fore.GREEN + "You guessed the correct number!")
os.system('clear')
else:
w(Fore.RED + "Sorry try again")
print(Fore.WHITE + "------------")
if guess > num:
w("your number is too large")
os.system('clear')
else:
w("your number is too small")
os.system('clear')
def rock_paper_scissors():
os.system('clear')
user_action = input(Fore.BLUE + "Pick your item (rock, paper, scissors): ")
w(Fore.WHITE + "you chose: " + user_action)
computer_choice = ["scissors", "paper", "rock"]
computer_choice = random.choice(computer_choice)
w(Fore.WHITE + "computer chose: " + computer_choice)
if user_action == computer_choice:
w(Fore.BLUE + f"Both players chose {user_action} its a tie!")
elif user_action == "rock":
if computer_choice == "scissors":
w(Fore.GREEN + "Player wins! Rock destroys Scissors.")
else:
w(Fore.RED + "Paper covers Rock! Computer wins.")
elif user_action == "paper":
if computer_choice == "rock":
w(Fore.GREEN + "Player wins! Paper covers Rock.")
else:
w(Fore.RED + "Scissors cut Paper! Computer wins.")
elif user_action == "scissors":
if computer_choice == "paper":
w(Fore.GREEN + "Player wins! Scissors cut Paper.")
else:
w(Fore.RED + "Rock destroys Scissors! Computer wins.")
os.system('clear')
play_again = input(Fore.CYAN + "Play again? y/n: ")
if play_again == ("y"):
os.system('clear')
rock_paper_scissors()
else:
os.system('clear')
choices()
The error is in this game
def cowboy_game():
os.system('clear')
#----cowboy game code-------
user_action = input("pick your move: ")
os.system('clear')
computer_choice = ["shoot", "reload", "guard"]
computer_choice = random.choice(computer_choice)
w("player chose: " + str(user_action))
w("computer chose: " + str(computer_choice))
#random if statement so elif will work since python is retarded in that way
fgf = print("")
if fgf == ("f"):
print("")
elif user_action == "shoot":
if computer_choice == "shoot":
print(Fore.WHITE + "Both Players killed each other. ")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
It prints the statement above
elif user_action == "shoot":
if computer_choice == "reload":
print(Fore.WHITE + "Player killed enemy.")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif user_action == "shoot":
if computer_choice == "guard":
print(Fore.WHITE + "Enemy blocked the bullet. No damage.")
cowboy_game()
os.system('clear')
It doesn't print at all for those statments
w(Fore.WHITE + "Welcome to my game hub! Pick a number to start ")
os.system('clear')
print("----------")
def choices():
print(Fore.CYAN + "1) Rock Paper Scissors")
print(Fore.WHITE + "----------")
print(Fore.CYAN + "2) Guess the number")
print(Fore.WHITE + "----------")
print(Fore.CYAN + "3) Cowboy game")
print(Fore.WHITE + "---------")
choices()
choice = input("Choice: ")
if choice == ('1'):
os.system('clear')
w("Everyone knows how to play this. Have fun!")
rock_paper_scissors()
if choice == ('2'):
os.system('clear')
w("Welcome to Guess the Number! Try and guess the number to play")
guess_the_number()
if choice == ('3'):
os.system('clear')
w("--(Welcome to cowboy! Instructions in the next line)--")
os.system('clear')
w("To shoot you need to reload first. choices: reload, guard, or shoot. What these do
are self explanatory lol")
w(Fore.CYAN + "press enter to start the game")
os.system('clear')
w(Fore.BLUE + "have fun! :)")
os.system('clear')
cowboy_game()
I cannot find anything online to help with this so I'm going to leave it up to the users on this site.
Solution 1:[1]
Your conditions for the Elif statements are the same. try:
elif user_action == "shoot":
if computer_choice == "shoot":
print(Fore.WHITE + "Both Players killed each other. ")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif computer_choice == "reload":
print(Fore.WHITE + "Player killed enemy.")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif computer_choice == "guard":
print(Fore.WHITE + "Enemy blocked the bullet. No damage.")
cowboy_game()
os.system('clear')
elif user_action == "reload":
(rest of your edge cases)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
