raw-input

Raw Input If Statements Python [duplicate]

纵然是瞬间 提交于 2019-12-17 17:28:19
问题 This question already has answers here : How can I read inputs as numbers? (10 answers) Closed last year . I am having trouble with if statements in python. I am making a "game" entirely in dolan speak, excuse the spelling, it meant to be humorous manner. Sorry. Here is the code: import time def menu(): print ("dogz r a supar hahrd tin 2 matsr it tak yrs 2 mastr ut u nw git 2 exprince it. pik a tin 2 du:\n") menu = raw_input("1.)Ply Da Dogi gam\n2.)Halp\n") if menu == 1: game() if menu == 2:

Behaviour of raw_input()

人盡茶涼 提交于 2019-12-17 06:56:32
问题 I wanted to understand the behaviour of raw_input in the below code. I know num will be string. Irrespective of whatever number i enter it always enter the elif part i.e. if num is 5, which should go to if num<check: part or if num is 10 which should go to else part. Every single time it is going to elif . I thought comparing STRING and INT might throw exception( I dont think so) but just in case, so I had included try except but as expected it did not throw any exception. But what puzzles me

How to let a raw_input repeat until I want to quit?

梦想的初衷 提交于 2019-12-17 04:08:28
问题 Say I want to use raw_input like this: code = raw_input("Please enter your three-letter code or a blank line to quit: ") under: if __name__=="__main__": How can I let it repeat multiple times rather than just once every time I run the program? Another question is to write what code can satisfy the condition "or a blank line to quit (the program)". 回答1: best: if __name__ == '__main__': while True: entered = raw_input("Please enter your three-letter code or leave a blank line to quit: ") if not

Tab completion in Python's raw_input()

人走茶凉 提交于 2019-12-17 03:52:38
问题 i know i can do this to get the effect of tab completion in python sure. import readline COMMANDS = ['extra', 'extension', 'stuff', 'errors', 'email', 'foobar', 'foo'] def complete(text, state): for cmd in COMMANDS: if cmd.startswith(text): if not state: return cmd else: state -= 1 readline.parse_and_bind("tab: complete") readline.set_completer(complete) raw_input('Enter section name: ') I am now interested in doing tab completion with directories. (/home/user/doc >tab) How would i go about

Why while loop is sticking at raw_input? (python)

不羁岁月 提交于 2019-12-14 01:32:33
问题 In the following code i am trying to make a "more" command (unix) using python script by reading the file into a list and printing 10 lines at a time and then asking user do you want to print next 10 lines (Print More..). Problem is that raw_input is asking again and again input if i give 'y' or 'Y' as input and do not continue with the while loop and if i give any other input the while loop brakes. My code may not be best as am learning python. import sys import string lines = open('/Users

Python raw_input with forced TLD?

怎甘沉沦 提交于 2019-12-13 15:17:26
问题 I am working on a program that checks hostnames of specific sites, and I want to be able to insure that when asked for the hostname (with raw_input ) it ends in a TLD ( .com , .net , .org ). I am not exactly sure how to do this in Python. In bash I have: local TLD=(com info org net) for entry in ${TLD[@]}; do blah blah done What is the equivalent in Python? 回答1: endswith(suffix[, start[, end]]) will do the trick. Documentation Please also note that suffix can be a tuple of suffices! TLD = ('

How to use raw_input() with while-loop

别说谁变了你拦得住时间么 提交于 2019-12-13 13:31:58
问题 Just trying to write a program that will take the users input and add it to the list 'numbers': print "Going to test my knowledge here" print "Enter a number between 1 and 20:" i = raw_input('>> ') numbers = [] while 1 <= i <= 20 : print "Ok adding %d to numbers set: " % i numbers.append(i) print "Okay the numbers set is now: " , numbers However when I execute the program it only runs to raw_input() Going to test my knowledge here Enter a number between 1 and 20: >>> 4 Is there some

Asyncore loop and raw_input problem

故事扮演 提交于 2019-12-12 10:37:49
问题 I'm trying to learn asyncore module. So I decided to develop a chat program. I have to listen the network and broadcast udp packages same time. But problem is while user typing a message, user cannot see other messages that sent by another users. What should I do? My code: #!/usr/bin/python # -*- coding: utf-8 -*- import asyncore import socket class Listener(asyncore.dispatcher): def __init__(self, port): asyncore.dispatcher.__init__(self) self.port = port self.create_socket(socket.AF_INET,

Difference between python script output and python console output

怎甘沉沦 提交于 2019-12-12 02:49:08
问题 I have this .py file: from sys import argv script, filename = argv print "We're going to erase %r." % filename print "If you don't want that, hit CTRL-C (^C)." print "If you do want that, hit RETURN." raw_input("?") print "Opening the file..." target = open(filename, 'w') print "Truncating the file. Goodbye!" target.truncate() print "Now I'm going to ask you for three lines." line1 = raw_input("line 1: ") line2 = raw_input("line 2: ") line3 = raw_input("line 3: ") print "I'm going to write

TypeError: can't multiply sequence by non-int of type 'float' python 2.7

非 Y 不嫁゛ 提交于 2019-12-12 00:26:28
问题 Hi I'm a 11 year old who has taken up python as a hobby. I'm trying to make a mass converter as a first project. But for some reason I've been getting this error: TypeError: can't multiply sequence by non-int of type 'float' Here is my code: print "please enter the amount of kilograms you want to convert", kilo = raw_input() pounds = 2.20462 print kilo * pounds 回答1: raw_input returns a string, you're basically doing this: print "1234" * 2.20462 You need to convert the input to a number: kilo