Python script with a peculiar if and Else condition problem

Asked

Viewed 481 times

-2

Hello, gentlemen(the).

I’m a beginner in programming and I’m learning Python.

I wanted to ask a question about a program I created.

The program must create a fully filled tuple with an extension count, from zero to twenty. The program should then read a number on the keyboard (between 0 and 20) and display it in full. At the end of the program it should be shown if the user wants to continue typing (Conditions S (for yes) or N (for no).

I was able to complete the program partially, but note that when I put the program to "run" the non-identification error of the "if" condition is forgotten in the user’s first typing after the user has entered a non-existent option for the program. Only the second time he types N (saying he DOES NOT want to continue) is when the program actually finishesinserir a descrição da imagem aqui.

Follow the error in the image:

  • 3

    Please [Edit] ask and add the source code. For reading more about in Manual on how NOT to ask questions.

  • "put the source code" is put the source code as text - not as an image. When pasting code as an image, anyone trying to collaborate cannot copy snippets of their code to respond, or even create a version that works - and is limited only to the code that appears on the screen.. In short: edit the question, remove this image, paste your source code, select it and click the button {} to format the code. Repeat the process with traceback (error message).

1 answer

0

Friend, it happens because of the nature of your if's, one of them is whether the variable is 'N' and the other is whether the variable is not 'N', that is, if I press 'N' the first if will be true, and the second will also be true.

Consider using a if-elif

Browser other questions tagged

You are not signed in. Login or sign up in order to post.