a = int(input("Podaj pierwszą liczbę: "))
b = int(input("Podaj drugą liczbę: "))
c = int(input("Podaj trzecią liczbę: "))
if a >= b and a >= c:
print("Największa liczba to:", a)
elif b >= a and b >= c:
print("Największa liczba to:", b)
else:
print("Największa liczba to:", c)
Program porównuje liczby parami:
Użycie operatora >= pozwala uwzględnić sytuację, gdy liczby są równe.
tekst = input("Podaj tekst: ")
samogloski = "aeiouyAEIOUY"
licznik = 0
for znak in tekst:
if znak in samogloski:
licznik += 1
print("Liczba samogłosek:", licznik)
To proste i eleganckie rozwiązanie, które działa dla dowolnego tekstu.
def pole_kwadratu(a):
return a * a
bok = int(input("Podaj długość boku kwadratu: "))
print("Pole kwadratu:", pole_kwadratu(bok))
Wzór na pole kwadratu to a × a. Funkcja zwraca wynik obliczenia, a następnie program wypisuje obliczone pole.
lista = []
for i in range(5):
produkt = input("Podaj produkt: ")
lista.append(produkt)
print("\nLista zakupów:")
for p in lista:
print("-", p)
append().import random
tajna = random.randint(1, 20)
while True:
strzal = int(input("Zgadnij liczbę (1–20): "))
if strzal < tajna:
print("Za mało!")
elif strzal > tajna:
print("Za dużo!")
else:
print("Brawo! Trafiłeś!")
break
random.randint(1, 20) losuje liczbę z zakresu 1–20.while True działa, dopóki użytkownik nie trafi.break kończy grę, gdy liczba jest odgadnięta.a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))
if a >= b and a >= c:
print("The largest number is:", a)
elif b >= a and b >= c:
print("The largest number is:", b)
else:
print("The largest number is:", c)
The program compares the numbers in pairs:
Using the >= operator handles the case when numbers are equal.
text = input("Enter a text: ")
vowels = "aeiouyAEIOUY"
counter = 0
for letter in text:
if letter in vowels:
counter += 1
print("Number of vowels:", counter)
This is a simple and elegant solution that works for any text.
def square_area(a):
return a * a
side = int(input("Enter the length of the square's side: "))
print("Area of the square:", square_area(side))
The formula for the area of a square is a × a. The function returns the result of the calculation, and the program then prints the calculated area.
shopping_list = []
for i in range(5):
item = input("Enter a product: ")
shopping_list.append(item)
print("\nShopping list:")
for p in shopping_list:
print("-", p)
append().import random
secret = random.randint(1, 20)
while True:
guess = int(input("Guess the number (1–20): "))
if guess < secret:
print("Too low!")
elif guess > secret:
print("Too high!")
else:
print("Well done! You guessed it!")
break
random.randint(1, 20) draws a random number from the range 1–20.while True loop keeps running until the user guesses correctly.break statement ends the game once the number has been guessed.