Is there a way to display input prompt text with the index number of array by python?

Because I want to make user know what numbers he is inputting. I want to display it like this

for i in range(0,5):
    V[i]=int(input("Masukkan V ke ",i))
    U[i]=int(input("Masukkan V ke ",i))

It doesnt work. Because it doesn't want argument outside of ".." Is there an alternative way to code it or not?

1 answer

  • answered 2019-10-08 02:58 wjandrea

    Yes, you could cast to str then concatenate:

    ... input("Masukkan V ke " + str(i))
    

    Or use print instead:

    print("Masukkan V ke", i, end='')
    ... input()
    

    Or use str.format or printf-style formatting:

    ... input("Masukkan V ke {}".format(i))
    ... input("Masukkan V ke %s" % i)