Python Forum
Code giving same output no matter the input.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code giving same output no matter the input.
#2
flip is a number. call is a string. They will never be equal. You have to either change flip to a string or call to a number (int).

I don't like using meaningless numbers, so I make my coin have Heads and Tails instead of 1 and 2.
import random

coin = ('Heads', 'Tails')
call = input(f'Call it {coin}: ')
flip = random.choice(coin)
 
if flip[0] == call[0].upper():
    result = 'YOU WIN'
else:
    result = 'YOU LOSE' 
print(f'\nIt landed on {flip}. {result}')
Reply


Messages In This Thread
RE: Code giving same output no matter the input. - by deanhystad - Dec-20-2020, 12:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 438 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,340 Sep-24-2023, 05:03 AM
Last Post: deanhystad
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,147 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  output provide the filename along with the input file processed. arjunaram 1 990 Apr-13-2023, 08:15 PM
Last Post: menator01
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,676 Mar-27-2023, 07:38 AM
Last Post: buran
  I cannot able to see output of this code ted 1 799 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 1,048 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  Help Switching between keyboard/Mic input in my code Extra 1 1,148 Aug-28-2022, 10:16 PM
Last Post: deanhystad
  why I dont get any output from this code William369 2 1,185 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,217 Mar-11-2022, 09:24 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020