5 – Solutions

Einführung in Python und PsychoPy

Autor

Clemens Brunner

Veröffentlicht

6. November 2025

Übung 1

x = int(input("x: "))
y = int(input("y: "))

if x + y > 50:
    print("x + y > 50")
elif x + y < 50:
    print("x + y < 50")
else:
    print("x + y == 50")

Übung 2

def is_odd(x):
    if x % 2 == 1:
        return True
    else:
        return False

Oder kürzer:

def is_odd(x):
    return x % 2 == 1

Übung 3

lst = ["I", "love", "Python"]
for element in lst:
    print(element)
I
love
Python

Übung 4

for element in lst:
    for ch in element:
        print(ch, end="-")
I-l-o-v-e-P-y-t-h-o-n-

Übung 5

x = 5  # x = -11, x = 0
if x > 0:
    print("x is positive")
elif x < 0:
    print("x is negative")
else:
    print("x is equal to 0")
x is positive

Übung 6

while True:
    x = int(input("Enter an integer between 1 and 10: "))
    if 0 < x <= 10:
        break
    else:
        print("Invalid input. Please try again.")

print("You entered:", x)