Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

Zadania z programowania w python – lista 2

  1. Napisz program, który spyta użytkownika ile ma lat, a następnie wyświetli czy osoba ta jest młodzieżą, dzieckiem czy dorosłym (załóżmy, że dziecko ma mniej niż 12 lat, a dorosły więcej niż 18).
age = int(input("How old are you? "))
if age < 12:
    category = "a child"
elif 12 <= age <= 18:
    category = "a teenager"
else:
    category = "an adult"
    
print(f"You are {category}.")
  1. Napisz program, który oblicza pole i obwód koła o promieniu podanym przez użytkownika. Dla stałej π przyjmij wartość przybliżoną. Promień nie może być ujemny. W przypadku podania liczby ujemnej, program powinien wypisywać komunikat informujący o błędnej wartości i nic nie liczyć.
import math

radius = float(input("Enter the radius of the circle: "))

if radius < 0:
    print("Invalid value. The radius cannot be negative.")
else:
    area = math.pi * radius ** 2
    circumference = 2 * math.pi * radius
    
    print(f"Area of the circle: {area:.2f}")
    print(f"Circumference of the circle: {circumference:.2f}")
  1. Napisz program, w którym:
    – do zmiennej dana przypiszesz pewną liczbę
    – użytkownik będzie mógł podać z klawiatury dowolną liczbę całkowitą
    – jeżeli użytkownik trafi program wyświetli komunikat: Gratulacje!, a jeśli nie, to wyświetli napis określający czy podana liczba jest większa od danej czy
    mniejsza.
data = 42
number = int(input("Enter an integer: "))

if number == data:
    print("Congratulations!")
elif number > data:
    print("The number you entered is greater than the given number.")
else:
    print("The number you entered is less than the given number.")

4. Napisz program, który w odpowiedzi na podaną przez użytkownika liczbę będzie wyświetlał komunikat czy jest to liczba parzysta, czy nieparzysta.

number = int(input("Enter a number: "))

if number % 2 == 0:
    print("The number is even.")
else:
    print("The number is odd.")
  1. Napisz program, który będzie sprawdzał czy z podanych przez użytkownika trzech długości można zbudować trójkąt.
a = float(input("Enter the first length: "))
b = float(input("Enter the second length: "))
c = float(input("Enter the third length: "))

if a + b > c and a + c > b and b + c > a:
    print("The lengths can form a triangle.")
else:
    print("The lengths cannot form a triangle.")

Leave a Comment