Python Forum
Two arguments in input function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two arguments in input function
#1
Question 
In output, I would like to receive this kind of message:
Give the quotation of Math : 15
In Math you have : 15.0 /20
and so on

Can You help me please to find out the solution to this error?
   
Reply
#2
Please do not upload images of code/data/errors.
copy/paste as text and properly format using BBCode tags.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
As per Python's official documentation the input() function accepts a single argument. You need to create a string containing "Give the quotation of Math :", then feed input() with that argument.
« We can solve any problem by introducing an extra level of indirection »
Reply
#4
Hi,

generally speaking, you certainly want to learn more about Python's string formating. Leaving the error on the input function aside, the string formatting on the print function isn't the way to do it either. See https://docs.python.org/3/tutorial/input...formatting for details.

Regards, noisefloor
buran likes this post
Reply
#5
You should read up a bit on Python f-strings, for example here.

course = 'English'
grade = input('Give the quotation of  ', course)
The above give this error:

Quote:Traceback (most recent call last):
File "/usr/lib/python3.12/idlelib/run.py", line 580, in runcode
exec(code, self.locals)
File "<pyshell#16>", line 1, in <module>
TypeError: input expected at most 1 argument, got 2

You can fix this error:

# can fix the above using a so-called f-string
# input always returns a string
course = 'English'
grade = input(f'Give the quotation of  {course}') # enter a number like 11
print(f'grade for {course} = {grade} from 20')
print(f'grade is type {type(grade)}')
type(var) tells you what type of variable var is. The output of input() is always <class 'str'>, a string variable.

courses = ['English', 'Deutsch',  'Castellano', '中文', 'Python']
# shouldn't really give yourself grades
# I got these grades fair and square! Honest guv!
my_grades = ['19', '18', '17', '16', '1']

# use a so-called f-string to put values in a string
for index, course in enumerate(courses):
    print(f'index = {index}, course = {courses[index]}, my grade = {int(my_grades[index]) / 20}')
Using .split() you can get multiple entries from 1 input()
By default .split() splits a string on spaces, but you can tell split() to split on any character. Here I chose ,

# input only gives you a string value back
# to get multiple entries from input() you can use .split()
# then names will be a list split() and you get back a list
string = input('Enter the surnames separated by a , ') # enter something like: Jones,Schmidt,Fernández,朱
type(string) # returns <class 'str'>
names = input('Enter the surnames separated by a , ').split(',')
type(names) # returns <class 'list'>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using a For Loop to subtract numbers from an input function. Anunderling 9 2,819 Sep-22-2025, 08:56 PM
Last Post: deanhystad
  function arguments Curbie 2 1,043 Apr-30-2025, 05:23 PM
Last Post: Curbie
  Input function oldschool 1 1,255 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  difference between forms of input a list to function akbarza 6 3,499 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  calling external function with arguments Wimpy_Wellington 6 4,016 Jul-05-2023, 06:33 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 3,131 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Showing an empty chart, then input data via function kgall89 0 1,902 Jun-02-2022, 01:53 AM
Last Post: kgall89
  input function question barryjo 12 5,872 Jan-18-2022, 12:11 AM
Last Post: barryjo
  function with 'self' input parameter errors out with and without 'self' called dford 12 12,323 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Problem with input after function luilong 10 7,448 Dec-04-2021, 12:16 AM
Last Post: luilong

Forum Jump:

User Panel Messages

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