1

I kinda can't solve this task:

Create variables

  • int_num and get user input string of only digits
  • long_num and initialize it as an empty string

Create a while loop that runs as long as the input is all digits Inside the while loop

  • add int_num to the end of long_num
  • get user input for int_num again (inside while loop this time)

After the loop exits

  • print the value of long_num

Here's my code:

int_num = input("Enter digit: ")
long_num = ""

while int_num.isdigit() != True:
    int_num + long_num
    int_num = input("You have to enter a DIGIT (integer)!: ")
print(long_num)

I need an advice to solve that with only given information from the task.

Thank you!

IYSZ
  • 27
  • 4
  • 1
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Selcuk Dec 19 '19 at 00:44

1 Answers1

1

I see three problems but since this is probably homework I don't want to just drop out code.

1) int_num + long_num does an addition but throws away the result, you want to save the result.

2) int_num + long_num is in a place where it will only be done if int_num is NOT a digit. I think you want to it if it IS a digit.

3) your while loop exits as soon as you get a non-digit. I don't think that was your intent.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • In an other task i had to send the input from a to b and print b out. can't i do that the same way with int_num & long_num? – IYSZ Dec 19 '19 at 01:14