Skip to content

Commit 7af4166

Browse files
committed
update project structure
1 parent 1b519fc commit 7af4166

9 files changed

+258
-98
lines changed

Programs/AddTwoNumbers.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
# ================= Problem Description =================
2+
# This script prompts the user to enter two numerical values (integers or floating-point numbers).
3+
# It calculates and displays the sum of these values.
4+
#
5+
# 1. Displays a welcome message.
6+
# 2. Prompts for and reads two numerical inputs.
7+
# 3. Computes and displays their sum.
8+
#
9+
# ================= Input =================
10+
# - Two numerical values (integers or floating-point).
11+
#
12+
# ================= Output =================
13+
# - The sum of the two input values.
14+
#
15+
# Example:
16+
# Input:
17+
# 5
18+
# 7.5
19+
#
20+
# Output:
21+
# Sum of the given two numbers: 12.5
22+
# =========================================================
123

224
# ============= Solution 01 =============
325
# num1 = 10
426
# num2 = 20
5-
# print("Sum of given two numbers :", num1 + num2)
27+
# print("Sum of given two numbers:", num1 + num2)
628

729
# ============= Solution 02 =============
830
print("Welcome to TowSome programme")
9-
num1 = float(input("Enter first number :"))
10-
num2 = float(input("Enter second number :"))
11-
print("Sum of given two numbers :", num1 + num2)
31+
num1 = float(input("Enter first number: "))
32+
num2 = float(input("Enter second number: "))
33+
print("Sum of given two numbers:", num1 + num2)

Programs/CalculateSquareRoot.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# ================= Problem Description =================
2+
# This script calculates the square root of a user-provided number.
3+
#
4+
# 1. Displays the program name.
5+
# 2. Prompts the user to input a numerical value.
6+
# 3. Computes the square root of the input value.
7+
# 4. Displays the result.
8+
#
9+
# ================= Input =================
10+
# - A numerical value (integer or floating-point) for which the square root is to be calculated.
11+
#
12+
# ================= Output =================
13+
# - The square root of the input value.
14+
#
15+
# Example:
16+
# Input:
17+
# 16
18+
#
19+
# Output:
20+
# Square Root : 4.0
21+
# =========================================================
22+
123
# ============= Solution 01 =============
224
# print("Program Name : Calculate Square Root")
325
# num = float(input("Enter a number :"))

Programs/CheckLeapYear.py

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
1+
# ================= Problem Description =================
2+
# This script determines whether a given year is a leap year.
3+
# It prompts the user to enter a year and checks if it is a leap year based on the following criteria:
4+
# - A year is a leap year if it is divisible by 4 and not divisible by 100, or if it is divisible by 400.
5+
#
6+
# 1. Displays a welcome message.
7+
# 2. Prompts the user to input a year.
8+
# 3. Checks if the entered year is a leap year.
9+
# 4. Displays whether the year is a leap year or not.
10+
# 5. Asks the user if they want to retry or quit.
11+
#
12+
# The program continues to prompt for a new year until the user decides to quit or provides invalid input.
13+
#
14+
# ================= Input =================
15+
# - A year (integer value).
16+
#
17+
# ================= Output =================
18+
# - A message indicating whether the year is a leap year or not.
19+
# - Option to retry or quit after each result.
20+
#
21+
# Example:
22+
# Input:
23+
# Enter year: 2024
24+
# Output:
25+
# 2024 is a leap year!
26+
# Do you want to retry? (y/q): n
27+
# =========================================================
28+
129
print("Welcome to Leap Year programme!")
230

331
def check_leap_year(y):
432
if ((y % 4 == 0) and (y % 100 != 0)) or (y % 400 == 0):
5-
print(str(y) + " is a leap year !")
6-
retry = input("Do you want to retry? (y/q): ").lower()
7-
if retry != "y":
8-
quit()
33+
print(f"{y} is a leap year!")
934
else:
10-
print(str(y) + " is not a leap year")
11-
retry = input("Do you want to retry? (y/q): ").lower()
12-
if retry != "y":
13-
quit()
35+
print(f"{y} is not a leap year")
36+
retry = input("Do you want to retry? (y/q): ").lower()
37+
if retry != "y":
38+
quit()
1439

1540
while True:
16-
y = input("Enter year : ")
41+
y = input("Enter year: ")
1742
if y.isnumeric():
1843
y = int(y)
1944
check_leap_year(y)

Programs/CheckPrimeNumber.py

+42-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
1-
print("Welcome to Prime Number Checking programme!")
1+
# ================= Problem Description =================
2+
# This script determines whether a given number is a prime number.
3+
# A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
4+
#
5+
# 1. Displays a welcome message.
6+
# 2. Prompts the user to input a number.
7+
# 3. Checks if the entered number is a prime number.
8+
# 4. Displays whether the number is prime or not.
9+
# 5. Asks the user if they want to retry or quit.
10+
#
11+
# The program continues to prompt for new numbers until the user decides to quit.
12+
#
13+
# ================= Input =================
14+
# - A number (integer value).
15+
#
16+
# ================= Output =================
17+
# - A message indicating whether the number is a prime number or not.
18+
# - Option to retry or quit after each result.
19+
#
20+
# Example:
21+
# Input:
22+
# Enter number: 7
23+
# Output:
24+
# 7 is a prime number!
25+
# Do you want to retry? (y/q): n
26+
# =========================================================
227

3-
run = True
28+
print("Welcome to Prime Number Checking programme!")
429

5-
def check_primenumber():
6-
num = int(input("Enter number : "))
7-
8-
if num == 1 :
9-
print(str(num) + " is not a prime number")
30+
def check_prime_number():
31+
num = int(input("Enter number: "))
1032

33+
if num < 2:
34+
print(f"{num} is not a prime number")
1135
else:
12-
for i in range(2, num):
13-
if num % i == 0 :
14-
print(str(num)+" is not a prime number fdg1")
36+
for i in range(2, int(num**0.5) + 1):
37+
if num % i == 0:
38+
print(f"{num} is not a prime number")
1539
retry = input("Do you want to retry? (y/q): ").lower()
1640
if retry != "y":
17-
run = False
1841
quit()
19-
20-
else :
21-
break
22-
else :
23-
print(str(num) + " is a prime number! h")
24-
retry = input("Do you want to retry? (y/q): ").lower()
25-
if retry != "y":
26-
run = False
27-
quit()
28-
else :
29-
break
42+
return
43+
print(f"{num} is a prime number!")
3044

31-
while run :
32-
33-
check_primenumber()
45+
retry = input("Do you want to retry? (y/q): ").lower()
46+
if retry != "y":
47+
quit()
48+
49+
while True:
50+
check_prime_number()

Programs/DelivaryTime.py

+38-23
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,54 @@
1-
This problem was descrived by []
1+
# ================= Problem Description =================
2+
# This script calculates and displays the delivery time or date based on the order time.
3+
# The delivery time is determined as follows:
4+
# - If the order time is less than 6 hours, the delivery time is the current date.
5+
# - If the order time is 6 hours or more, the delivery date is the following day.
6+
#
7+
# 1. Prompts the user to input the order time in hours.
8+
# 2. Calculates the delivery time or date based on the order time.
9+
# 3. Displays the result.
10+
# 4. Asks the user if they want to retry or quit.
11+
#
12+
# The program continues to prompt for new order times until the user decides to quit or provides invalid input.
13+
#
14+
# ================= Input =================
15+
# - Order time (integer value representing hours).
16+
#
17+
# ================= Output =================
18+
# - Delivery time or date based on the order time.
19+
# - Option to retry or quit after each result.
20+
#
21+
# Example:
22+
# Input:
23+
# Enter order time: 3
24+
# Output:
25+
# Delivery time is: 2024-09-16
26+
# Do you want to retry? (y/q): n
27+
# =========================================================
228

329
from datetime import datetime, timedelta
430

531
# Get the current time without microseconds
632
current_date = datetime.now().strftime('%Y-%m-%d')
733
next_day_date = datetime.now().date() + timedelta(days=1)
834

9-
10-
11-
12-
def deliveryTimer (orderTime):
13-
if orderTime < 6 :
14-
print("Delivary time is : " + current_date)
15-
16-
retry = input("Do you want to retry? (y/q): ").lower()
17-
if retry != "y":
18-
quit()
35+
def delivery_timer(order_time):
36+
if order_time < 6:
37+
print(f"Delivery time is: {current_date}")
1938
else:
20-
print("Delivary date is : " + str(next_day_date))
21-
22-
retry = input("Do you want to retry? (y/q): ").lower()
23-
if retry != "y":
24-
quit()
25-
26-
39+
print(f"Delivery date is: {next_day_date}")
2740

41+
retry = input("Do you want to retry? (y/q): ").lower()
42+
if retry != "y":
43+
quit()
2844

2945
while True:
30-
orderTime = input("Enter order time : ")
31-
if orderTime.isnumeric():
32-
orderTime = int(orderTime)
33-
deliveryTimer(orderTime)
46+
order_time = input("Enter order time (in hours): ")
47+
if order_time.isnumeric():
48+
order_time = int(order_time)
49+
delivery_timer(order_time)
3450
else:
3551
print("Not a valid input")
3652
retry = input("Do you want to retry? (y/q): ").lower()
3753
if retry != "y":
3854
break
39-

Programs/QuizGame.py

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
print("Welcome to my computer quize!")
1+
# ================= Problem Description =================
2+
# This script implements a simple computer quiz game.
3+
# The user is prompted to play a quiz where they answer a question about computer hardware.
4+
#
5+
# 1. Greets the user and asks if they want to play.
6+
# 2. If the user responds with "yes", the quiz starts; otherwise, the program exits.
7+
# 3. Asks the user a question about what CPU stands for.
8+
# 4. Evaluates the user's answer and updates the score based on correctness.
9+
# 5. Displays the final score and ends the quiz.
10+
#
11+
# ================= Input =================
12+
# - User's response to the initial prompt ("yes" or any other response).
13+
# - User's answer to the quiz question.
14+
#
15+
# ================= Output =================
16+
# - Feedback on the correctness of the answer.
17+
# - The final score after the quiz.
18+
#
19+
# Example:
20+
# Input:
21+
# Do you want to play? yes
22+
# What does CPU stand for? central processing unit
23+
# Output:
24+
# Correct
25+
# Your score is 1
26+
# END
27+
# =========================================================
28+
29+
print("Welcome to my computer quiz!")
230

331
playing = input("Do you want to play? ")
432

@@ -8,13 +36,12 @@
836
print("Ok, let's play!")
937
score = 0
1038

11-
answer = input("What dose CPU stand for? ")
12-
if answer.lower() == "central processing unit" :
13-
print("Correct")
14-
score += 1
15-
else:
16-
print("Incorrct")
17-
39+
answer = input("What does CPU stand for? ")
40+
if answer.lower() == "central processing unit":
41+
print("Correct")
42+
score += 1
43+
else:
44+
print("Incorrect")
1845

19-
print("Your score is " + str(score))
20-
print("END")
46+
print(f"Your score is {score}")
47+
print("END")

Programs/SwapTwoVariables.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# ================= Problem Description =================
2+
# This script demonstrates two methods for swapping the values of two variables and checks if a number is even or odd.
3+
#
4+
# 1. **Variable Swapping**:
5+
# - Solution 01 swaps the values of two variables using a temporary variable.
6+
# - Solution 02 swaps the values of two variables using tuple unpacking.
7+
# 2. **Number Check**:
8+
# - Checks if a predefined number is even or odd and prints the result.
9+
#
10+
# ================= Input =================
11+
# - No user input is required for variable swapping.
12+
# - A predefined number is used for checking even or odd.
13+
#
14+
# ================= Output =================
15+
# - Displays the swapped values of the variables.
16+
# - Displays whether the predefined number is even or odd.
17+
#
18+
# Example:
19+
# Output for variable swapping:
20+
# x is 7 y is 5
21+
#
22+
# Output for number check:
23+
# Odd number
24+
# =========================================================
25+
126
# ============= Solution 01 =============
227
# x = 5
328
# y = 7
@@ -9,12 +34,12 @@
934
# ============= Solution 02 =============
1035
x = 5
1136
y = 7
12-
x,y =y ,x
37+
x, y = y, x
1338

14-
print("x is ", x, "y is ", y)
39+
print("x is", x, "y is", y)
1540

1641
number = 11
1742
if number % 2 == 0:
1843
print("Even number")
1944
else:
20-
print("Odd number")
45+
print("Odd number")

0 commit comments

Comments
 (0)