Python Forum
why doesnt the while loop run?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why doesnt the while loop run?
#4
>>> first = int(input())
5                      # I give an input that can be turned to an integer.
>>> first = int(input())
rock                   # Here the 'rock' word can't be turned to an integer of course so I get an error.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'rock'
If you want to map an integer to a word you can use a dictionary.
first = lower(input("rock paper scissors?: "))   # converting the input to lower case letters so you can used it as a key in the dict bellow
second = lower(input("rock paper scissors?: ")) 

r_p_s = {'rock': 5, 'paper': 10, 'scissors': 15}

while r_p_s['rock']:
    etc.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
why doesnt the while loop run? - by supermane - Aug-03-2018, 07:36 AM
RE: why doesnt the while loop run? - by wavic - Aug-03-2018, 08:06 AM
RE: why doesnt the while loop run? - by supermane - Aug-04-2018, 04:58 AM
RE: why doesnt the while loop run? - by wavic - Aug-04-2018, 06:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have two Same Code but One of them Doesnt Work beginner721 6 3,093 Jan-22-2021, 10:56 PM
Last Post: beginner721
  code doesnt return anything ofrihemo 3 2,040 Jun-30-2020, 05:14 PM
Last Post: ofrihemo
  Why does this work and this doesnt= puruvaish24 1 2,602 May-22-2018, 03:58 AM
Last Post: scidam
  Python code doesnt run tsetsko 3 3,795 Sep-02-2017, 01:47 PM
Last Post: tsetsko

Forum Jump:

User Panel Messages

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