i'm just writing a simple program that should give me a random integer between 1 and 10 if i input the value of 'r'in code. here's what i have:
import sys, random
from random import *
def randomly():
return (randint(1, 10))
while True:
x = input("input string ")
x = str(x)
print (x)
if x == 'r':
print ("your generated number is", randomly())
else:
break
i know there's just something small i'm overlooking. but i can't figure out what. the randomly function works. and if i replace the 'r' conditional with an integer (i used 1) convert x with int(x) and then input 1 the program works fine. like so:
import sys, random
from random import *
def randomly():
return (randint(1, 10))
while True:
x = input("input number ")
x = int(x)
print (x)
if x == 1:
print ("your generated number is", randomly())
else:
break
for some reason the if conditional won't respond to my string. i tried x.lower() and it still won't work, while it's true that just using the method i described before with the integer would work fine. it frustrates me that my code won't work the way i want it to. for what it's worth i checked len(x) and it says 2 when i input a single character(r). i'm fairly novice to python but i have the knowledge i need, at least, to write a program like this. any help would be greatly appreciated.
i'm using visual studio 2015 python environment: python 3.2
this is my first question here. i searched to the best of my capabilities and couldn't find an answer. i apologize in advance if there is anything wrong with my question.