0% found this document useful (0 votes)
31 views

Lab 4

This document discusses 12 programming exercises using Python. The exercises cover topics like positive/negative number identification, password validation, leap year determination, and exception handling using try/except blocks.

Uploaded by

Amr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lab 4

This document discusses 12 programming exercises using Python. The exercises cover topics like positive/negative number identification, password validation, leap year determination, and exception handling using try/except blocks.

Uploaded by

Amr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

================= Lab 4 ================

#==================== Lab 4 ========================

print(" Q.5 Do these Programming Exercises with Python language to:")

# print('========= lab4 Q.5 (1) =========\n')


# #1. Write a python program to print a number is positive/negative using if-
else.
#
# number = int(input("Enter the number : "))
#
# if number > 0 :
# print("The number (",number ,") is : 'positive .' ")
# elif number < 0 :
# print("The number (",number ,") is : Negative . ")
# elif number == 0 :
# print("The number (",number ,") is : Zero . ")
# else:
# print(" \tError ..... ")
#
# print("=============================================")

# print('========= lab4 Q.5 (2) =========\n')


# # 2.Make a program that asks the number between 1 and 10
# lf the number is out of range the program should display "invalid number".
#
# number = int(input("Enter a number between 1 and 10 : "))
#
# if number < 1 or number > 10 :
# print("The number (",number ,") is not included . ")
# else:
# print(" The number is included ")
#
# print("=============================================")

# print('========= lab4 Q.5 (3) =========\n')


# # 3.Makea program thatasksa password.
#
# password_list = ["123"]
# password = input("Enter the password : ")
#
# if password in password_list :
# print("The password is correct. \n\n\t Welcome to the system....")
# else:
# print("Sorry, the password is incorrect.")
#
# print("=============================================")

# print('========= lab4 Q.5 (4) =========\n')


# # 4. Implement python script to read person's age from
# keyboard and display whether he is eligible for voting or not.
#
# age_person = int(input("Enter the age : "))
# required_age = 25
#
# if age_person >= required_age :
# print("You have been accepted. ")
# else:

‫الم‬
‫ رقنة سلمان و سدى الورد‬/ ‫هندسيان‬ ‫ ضياء احمد علي الش فري‬/ ‫الطالب‬
================= Lab 4 ================

# print("You age is not acceptable. ")


#
# print("=============================================")

#print('========= lab4 Q.5 (5) =========\n')


# # 5. Implement python script to chec:k the given year is leap year or not.
#
# year = int(input("Enter a year: "))
#
# if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
# print(year, " is a leap year")
# else:
# print(year, " is not a leap year")
#
# print("=============================================")

# print('========= lab4 Q.5 (6) =========\n')


# # 6. Check user input is a positive number or negative
#
# number = float(input("Enter a number : "))
#
# if number > 0:
# print("The number is positive")
# elif number < 0:
# print("The number is negative")
# else:
# print("The number is zero")
#
# print("=============================================")

#print('========= lab4 Q.5 (7) =========\n')


# # 7. Write a python program to find largest number among three numbers.
#
# num1 = float(input("Enter the first number: "))
# num2 = float(input("Enter the second number: "))
# num3 = float(input("Enter the third number: "))
#
# if num1 >= num2 and num1 >= num3:
# largest = num1
# elif num2 >= num1 and num2 >= num3:
# largest = num2
# else:
# largest = num3
#
# print("The largest number is:", largest)
#
# print("=============================================")

#print('========= lab4 Q.5 (8) =========\n')


# # 8. Write a python Program to read
# a number and display corresponding day using if elif else?
#
# number = int(input("Enter the day number (1-7): "))
#
# if number == 1:
# print("The corresponding day is Saturday")
# elif number == 2:

‫الم‬
‫ رقنة سلمان و سدى الورد‬/ ‫هندسيان‬ ‫ ضياء احمد علي الش فري‬/ ‫الطالب‬
================= Lab 4 ================

# print("The corresponding day is Sunday")


# elif number == 3:
# print("The corresponding day is Monday")
# elif number == 4:
# print("The corresponding day is Tuesday")
# elif number == 5:
# print("The corresponding day is Wednesday")
# elif number == 6:
# print("The corresponding day is Thursday")
# elif number == 7:
# print("The corresponding day is Friday")
# else:
# print("Invalid day number. Please enter a number between 1 and 7")
#
# print("=============================================")

#print('========= lab4 Q.5 (9) =========\n')


# # 9. What Are the optional statements possible inside
# a try-except block in Python The ''else" clause The ''finally" clause
#
# # try:
# # # ‫استثناء حدوث يحتمل كود‬
# # except SomeException:
# # # ‫معين استثناء لمعالجة كود‬
# # else:
# # # ‫استثناء رفع يتم لم إذا تنفيذه يجري كود‬
# # finally:
# # # ‫ًا تنفيذه يجري كود‬
‫ال أو استثناء رفع كان إذا عما النظر بغض دائم‬
#
#
# # ‫مثــــــــــال‬
# try:
# number = int(input("Enter a number: "))
# result = 10 / number
# except ValueError:
# print("Invalid input. Please enter a valid number.")
# except ZeroDivisionError:
# print("Error: Division by zero is not allowed.")
# else:
# print("Result:", result)
# finally:
# print("Program execution completed.")
#
#
# print("=============================================")

#print('========= lab4 Q.5 (10) =========\n')


# # 10.Write a python program to check whether the given string is palindrome or
not.
#
# input_string = input("Enter the string: ")
#
# string = ''.join(e for e in input_string if e.isalnum()).lower()
#
# if string == string[::-1]:
# print("The string is a palindrome.")
# else:
# print("The string is not a palindrome.")
#

‫الم‬
‫ رقنة سلمان و سدى الورد‬/ ‫هندسيان‬ ‫ ضياء احمد علي الش فري‬/ ‫الطالب‬
================= Lab 4 ================

# print("=============================================")

#print('========= lab4 Q.5 (11) =========\n')


# #11. Demonstrate a python code to implement abnormal termination?
#
# # ‫ بإستخدام‬def
# def divide_numbers(a,b) :
# try:
# result = a / b
# return result
# except ZeroDivisionError:
# print("Error: Division by zero! ")
# raise
#
# numerator = 10
# denominator = 0
#
# try:
# result = divide_numbers(numerator, denominator)
# print("Result is :",result)
# except:
# print("An error occurred. Abonrmal terminaton. ")
#
#
# # ‫ استخدام بدون‬def
#
# numerator = int(input("Enter the number 1 : "))
# denominator = int(input("Enter the number 2 : "))
#
# try:
# result = numerator / denominator
# print("Result is :",result)
# except ZeroDivisionError:
# print("Error: Division by zero! ")
#
# except:
# print("An error occurred. Abonrmal terminaton. ")
#
# print("=============================================")

#print('========= lab4 Q.5 (12) =========\n')


# #12. Demonstrate a python code to print try, except and finally block statements
#
# def divide_numbers(a, b):
# try:
# result = a / b
# print("Result is :", result)
# except ZeroDivisionError:
# print("Error: Division by zero! ")
# finally:
# print("Finally block excepted. ")
#
# numerator = 10
# denominator = 2
# divide_numbers(numerator, denominator)
#
#‫اخرى تنسيق طريقة‬ ==============
#
# num1 = int(input("Enter the number 1 : "))

‫الم‬
‫ رقنة سلمان و سدى الورد‬/ ‫هندسيان‬ ‫ ضياء احمد علي الش فري‬/ ‫الطالب‬
================= Lab 4 ================

# num2 = int(input("Enter the number 2 : "))


#
# try:
# result = num1 / num2
# print("Result is :", result)
# except ZeroDivisionError:
# print("Error: Division by zero! ")
# else:
# print("Done.....")
# finally:
# print("Finally block excepted. ")
#
#
# print("=============================================")

print(" ========== Question (5) completed ============")

‫الم‬
‫ رقنة سلمان و سدى الورد‬/ ‫هندسيان‬ ‫ ضياء احمد علي الش فري‬/ ‫الطالب‬

You might also like