Aumedi Wibisana
Aumedi Wibisana

Reputation: 11

TypeError: raw_input() takes from 1 to 2 positional arguments but 3 were given

I was trying to find the average height of n number of children. I wanted to make the input says "Enter the height of children number A", where A is an arbitrary integer (1, 2, 3,...) which indicate the A-th children. I have designed my code this way, which somehow ended up to this error (shown in the title). I would appreciate any help :).

jmlh_anak = int(input("Enter n number of children : "))
A = 1
jmlh_tinggi = 0

while (A <= jmlh_anak):
  nilai_tinggi = int(input("Enter the height of children number ", str(A)))
  jmlh_tinggi += nilai_tinggi
  A += 1

rtrt_tinggi = jmlh_tinggi / jmlh_anak
print("The average of the children's height will be", rtrt_tinggi)

I was expecting the input for the children's height would say "Enter the height of children number 1 : " for example.

Upvotes: -1

Views: 26246

Answers (3)

Vince
Vince

Reputation: 1

You can use:

nilai_tinggi = int(input(f"Enter the height of children number {A}: "))

Upvotes: 0

Rashi Sheth
Rashi Sheth

Reputation: 1

Since string and integers cannot be connected together directly you need to convert the integer into a string first and then use it in the input statement.

you can use the statement as:

nilai_tinggi = int(input("Enter the height of children number "+ str(A)))

Upvotes: -1

Learning is a mess
Learning is a mess

Reputation: 8277

Use:

nilai_tinggi = int(input("Enter the height of children number %d" %A))

for string formatting.

Upvotes: 0

Related Questions