0% found this document useful (0 votes)
6 views2 pages

Python

Uploaded by

Awais Javed
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)
6 views2 pages

Python

Uploaded by

Awais Javed
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/ 2

PYTHON:

Assignment

Name: Taha Siddique

ID: F-2023387016

Question: Write a program that display the table of integer number entered by user. Create 3
functions, one will print out the ascending order of table, 2) will take a new number and print
descending order and the third function will get the sum of table from ascending and
descending order and then displays the odd and even numbers between their sums.

Code:

def print_table_and_sum(num, start, end, order="ascending"):


total_sum = 0
if order == "ascending":
print("\nAscending order:")
for i in range(start, end + 1):
print(f"{num} * {i} = {num * i}")
total_sum += num * i
print(total_sum)
elif order == "descending":
print("\nDescending order:")
for i in range(start, end - 1, -1):
print(f"{num} * {i} = {num * i}")
total_sum += num * i
print(total_sum)
return total_sum
def print_odd_even_between(asc_sum, desc_sum):
low, high = min(asc_sum, desc_sum), max(asc_sum, desc_sum)
print(f"\nOdd numbers between {low} and {high}:")
for i in range(low + 1, high):
if i % 2 != 0:
print(i, end=" ")
print("\nEven numbers between {low} and {high}:")
for i in range(low + 1, high):
if i % 2 == 0:
print(i, end=" ")
print()
while True:
print("\nFor ascending order:")
asc_num = int(input("Enter the table number: "))
asc_start = int(input("Enter the starting value: "))
asc_end = int(input("Enter the ending value: "))
asc_sum = print_table_and_sum(asc_num, asc_start, asc_end, order="ascending")
print("\nFor descending order:")
desc_num = int(input("Enter the table number: "))
desc_start = int(input("Enter the starting value: "))
desc_end = int(input("Enter the ending value: "))
desc_sum = print_table_and_sum(desc_num, desc_start, desc_end, order="descending")
print_odd_even_between(asc_sum, desc_sum)
choice = input("\nWould you like to enter another table? (y/n): ")
if choice.lower() != 'y':
print("Exiting the program.")
break

You might also like