0

I am very new at coding so sorry if my code bellow annoys you lol but I was wondering if there is any way to include more than 1 argument in the raw_input() function so that I wouldn't have to do

print("Do you want to filter numbers greater or lower that ", filt, "?")
gorl = raw_input()

rather than just

gorl = raw_input("Do you want to filter numbers greater or lower than ", 
filt, "?")

my entire code is

import random
import sys
import os

filt = int(raw_input("What number do you want your results to be filtered 
by?"))

gorl = raw_input("Do you want to filter numbers greater or lower than ", 
filt, "?")

ammvar = int(raw_input("How many variables do you want to filter?"))

var_list = []

varnum = 1

while ammvar > 0:
    var_list.append(int(raw_input("Variable ", varnum, ":")))
    varnum + 1
    ammvar - 1

and this is what eclipse returns when I run it

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ What number do you want your results to be filtered by?10

Do you want it to be filtered greater or lower?greater

How many variables do you want to filter?7

Traceback (most recent call last):

File "C:\Users\D\workspace\Simple\Sorter__init__.py", line 16, in

var_list.append(int(raw_input("Variable ", varnum, ":")))

TypeError: raw_input() takes at most 1 argument (3 given) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

IIlIll IIIlII
  • 51
  • 1
  • 6
  • `raw_input("Do you want to filter numbers greater or lower than {} ?".format(filt))` – cs95 Dec 12 '17 at 14:45
  • `print()` explicitly takes a variable number of arguments, writing them all out as strings with a separator between. `raw_input()` doesn't do that, just for a single string first. You could use string templates (`str.format()`) or concatenation for that. Or just print without a newline at the end with `print(...., end='')` then run a `raw_input()` command with no string. – Martijn Pieters Dec 12 '17 at 14:45
  • Use string formatting to insert parameters into strings. – cs95 Dec 12 '17 at 14:45
  • Ok, didn't think about that sorry, thank you so much! – IIlIll IIIlII Dec 12 '17 at 14:47
  • See [format-examples](https://docs.python.org/3.4/library/string.html#format-examples) – Patrick Artner Dec 12 '17 at 14:48

0 Answers0