Posts

Showing posts with the label while-loop

while/try/except decimal TypeError not working

while/try/except decimal TypeError not working I thought I could finally get some use out of the while/try/except loop, but I am encountering a problem. My task is to have the computer request numbers from a user until '0' is entered. After this, the numbers entered will be added. My problem is that the Except part isn't catching non-numeric entries. If a non-numeric entry is entered, I get a regular error message that stops the program. Here is what happens when I enter 3 numbers and the 4th entry is 'm': on win32 Type "copyright", "credits" or "license()" for more information. >>> RESTART: C:/Users/Username/Documents/CISPROG1/Homework 5/Homework5.1.SumGenerator.py Enter 1st element (or type '0' to finish). 1 Enter 2nd element (or type '0' to finish). 2 Enter 3rd element (or type '0' to finish). 3 Enter 4th element (or type '0' to finish). m Traceback (most recent call last): File "C:/...

Use of while loop in this code while reading an input of a whole line using scanner? [on hold]

Use of while loop in this code while reading an input of a whole line using scanner? [on hold] enter image description here how can we concatenate the two strings, one of them is initialized in code and other string is the user input? This question appears to be off-topic. The users who voted to close gave this specific reason: Post the code here please – user7 Jul 1 at 4:31 Please read Minimal, Complete, and Verifiable example and enhance your question accordingly. And never ever link to pictures of code or error messages. They are text and need to be in the question. – GhostCat Jul 1 at 4:33 Hint: the + operator does String concatenation. – Step...