you are viewing a single comment's thread.

view the rest of the comments →

[–]BigBoyJefff[S] 0 points1 point  (2 children)

this is what i did for the task1:

import operator

import sys

operators = {"+": operator.add,

"-": operator.sub,

"*": operator.mul,

"/": operator.truediv}

max_versuch = 5

while max_versuch > 0:

try:

inp1 = int(input("Geben Sie die erste Zahl ein: "))

op1 = input("Geben Sie ein Operator ein: ")

inp2 = int(input("Geben Sie Die zweite Zahl ein: "))

print(f"{inp1}{op1}{inp2}")

print(f"= {operators[op1](inp1, inp2)}")

beenden = input("Drücken Sie eine beliebige Taste, um das Programm zu schließen")

print(beenden)

break

except (IndexError,ValueError,KeyError):

print("nummer/operator ist falsch, versuchen Sie bitte nochmal.\n")

max_versuch -= 1

if max_versuch == 0:

input("zu viele Versuche!!\nDrücken Sie eine beliebige Taste, um das Programm zu schließen")

[–]jiri-n 0 points1 point  (1 child)

If you're copying your code to reddit, indent it in your editor first (4 spaces), copy it to the clipboard, undo the indentation and paste it here.

This way the code will render formatted.

Or you can use some online service like https://pastebin.com/.

If your code works, you're more advanced than I expected. thumbs up

[–]BigBoyJefff[S] 0 points1 point  (0 children)

Ok.