From f9ca22b7b4351e1ae6fe7729e0947ead55658f00 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:36:33 +0530 Subject: [PATCH 01/32] Solved problem 1 --- problems/easy/easy_q1.py | 2 +- problems/easy/easy_q10.py | 4 ++-- problems/easy/easy_q11.py | 4 ++-- problems/easy/easy_q12.py | 12 ++++++------ problems/easy/easy_q2.py | 4 ++-- problems/easy/easy_q3.py | 4 ++-- problems/easy/easy_q4.py | 4 ++-- problems/easy/easy_q5.py | 8 ++++---- problems/easy/easy_q6.py | 6 +++--- problems/easy/easy_q7.py | 4 +++- problems/easy/easy_q8.py | 6 +++--- problems/easy/easy_q9.py | 6 +++--- problems/medium/m1.py | 11 ++++++----- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 711a7ba..fdfc3bf 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -2,10 +2,10 @@ def is_palindrome(num): original = num reverse = 0 - do: + while num != 0: reverse = reverse * 10 + num % 10 num //= 10 - while num != 0 + return reverse == original if __name__ == "__main__": nums = int(input("Enter the Number: ")) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 667d8e9..8d04363 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -9,10 +9,10 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } - return switch[8] + return switch[day] if __name__ == "__main__": - xcd = day_of_week(32) + xcd = day_of_week(1) print(xcd) diff --git a/problems/easy/easy_q12.py b/problems/easy/easy_q12.py index 85f2ebf..d8a50d6 100644 --- a/problems/easy/easy_q12.py +++ b/problems/easy/easy_q12.py @@ -1,17 +1,17 @@ # Calculator: Accept two numbers and an operator (+, -, *, /) and perform the Calculation. def calculator(a, b, operator): switch = { - '+': a - b, - '-': a * b, - '*': a / b, - '/': a + b + '+': a + b, + '-': a - b, + '*': a * b, + '/': a / b } - return switch.get(operator, "Invalid Operator") + return switch.get(operator , "Invalid Operator") if __name__ == "__main__": n1 = int(input("Enter the Number 1 :")) n2 = int(input("Enter the Number 2 :")) opr = input("Enter the Operator :") - result = calculator(opr,n2,n1) + result = calculator(n1,n2,opr) print(result) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..119ac31 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,9 +1,9 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a + return b if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..0143c1d 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,8 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + return "Leap Year" + return "Not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..924bf94 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,8 +1,8 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): - if num > 0: + if num < 0: print("Negative") - elif num < 0: + elif num > 0: print("Positive") else: print("Number is negative") diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..9c7b371 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,13 +2,13 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "F" if __name__ == "__main__": num = input("Enter the Mark : ") diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..09dc1d2 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,9 +3,9 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 + i += 1 if __name__ == "__main__": num = int(input("Enter the Number ")) - res = print_numbers(num) - print(res) + print_numbers(num) + diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..9961194 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -3,10 +3,12 @@ def sum_of_digits(num): total = 0 while num > 0: total += num % 10 - num = num + 10 + num = num // 10 return total if __name__ == "__main__": num = int(input("Enter the Number : ")) + res=sum_of_digits(num) + print(res) diff --git a/problems/easy/easy_q8.py b/problems/easy/easy_q8.py index 794332a..526f5ab 100644 --- a/problems/easy/easy_q8.py +++ b/problems/easy/easy_q8.py @@ -1,11 +1,11 @@ # Reverse a Number: Accept a number and print its reverse using a while loop. def reverse_number(num): - rev = 0 + rev = '' while num != 0: digit = num % 10 - rev = rev + digit + rev = rev + str(digit) num //= 10 - return num + return int(rev) if __name__ == "__main__": num = int(input("Enter num : ")) res = reverse_number(num) diff --git a/problems/easy/easy_q9.py b/problems/easy/easy_q9.py index 96af443..c41f28d 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -3,11 +3,11 @@ def factorial(n): result = 1 while n > 0: result *= n - n += 1 + n -= 1 return result if __name__ == "__main__": num = int(input("Enter the Number :")) - factorial(num*7) - print(num) + print(factorial(num)) + diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..46de4b9 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,17 +10,18 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split()) + a, b = map(int, input("Enter two numbers: ").split(',')) - if choice == 1: + if choice == 2: print("Subtraction:", a - b) - elif choice == 2: + elif choice == 1: print("Addition:", a + b) - elif choice == 3: - print("Division:", a / b) elif choice == 4: + print("Division:", a / b) + elif choice == 3: print("Multiplication:", a * b) elif choice == 5: print("Modulo:", a // b) else: print("Invalid option") +math_operations_menu() \ No newline at end of file From 22476e3042b74b7d597e4407b6510533864fbf9b Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:37:28 +0530 Subject: [PATCH 02/32] Solved problem 1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 46de4b9..7611467 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -8,7 +8,7 @@ def math_operations_menu(): print("3. Multiply") print("4. Divide") print("5. Modulo") - choice = int(input("Enter your choice: ")) + choice = int(input("Enter your choice: ")) a, b = map(int, input("Enter two numbers: ").split(',')) From 3c4becff83657ea54151dd6b8589e6568f57bb52 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:41:49 +0530 Subject: [PATCH 03/32] Solved problem 1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 7611467..46de4b9 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -8,7 +8,7 @@ def math_operations_menu(): print("3. Multiply") print("4. Divide") print("5. Modulo") - choice = int(input("Enter your choice: ")) + choice = int(input("Enter your choice: ")) a, b = map(int, input("Enter two numbers: ").split(',')) From 126e094f5be4b451b4a5746407abf323cc489847 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:46:52 +0530 Subject: [PATCH 04/32] Solved problem m1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 46de4b9..821e075 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,7 +10,7 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split(',')) + a, b = map(int, input("Enter two numbers (Comma seperated): ").split(',')) if choice == 2: print("Subtraction:", a - b) From 47cf47bb98e6e41fa0f4fb970bc3d1a4261c1e22 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 13:42:22 +0530 Subject: [PATCH 05/32] resolving leap prob --- problems/easy/easy_q3.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..953e617 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): - if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): + return "Leap Year" + else: + return "Not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) From ecfbab5ecbb8ae44eccd4172caf1a286c038410a Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 13:45:37 +0530 Subject: [PATCH 06/32] Solved problem 2 --- problems/medium/m2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/problems/medium/m2.py b/problems/medium/m2.py index d2007a7..e5a6758 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -8,12 +8,14 @@ def array_operations_menu(): arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: - print("Sum:", sum(arr) * 2) + print("Sum:", sum(arr)) elif choice == 2: - print("Largest Element:", min(arr)) + print("Largest Element:", max(arr)) elif choice == 3: - print("Smallest Element:", max(arr)) + print("Smallest Element:", min(arr)) elif choice == 4: + arr.sort() print("Sorted Array:", arr) else: print("Invalid option") +array_operations_menu() \ No newline at end of file From fec59e8e8e4936818d6f310e0c43c3734a456694 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 13:51:27 +0530 Subject: [PATCH 07/32] resolving largest num --- problems/easy/easy_q2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..ec4d7b3 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,11 +1,11 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a + return b if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) \ No newline at end of file From 8918dc88720481de4a60b41567c9ec3fe05320a7 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 13:53:26 +0530 Subject: [PATCH 08/32] Solved problem --- problems/medium/m3.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/problems/medium/m3.py b/problems/medium/m3.py index b0e1d2c..5d5d7b8 100644 --- a/problems/medium/m3.py +++ b/problems/medium/m3.py @@ -12,18 +12,19 @@ def string_manipulation_menu(): count = 0 for char in s: if char in vowels: - count -= 1 + count += 1 print("Number of Vowels:", count) elif choice == 2: - print("Reversed String:", s[1::-1]) + print("Reversed String:", s[::-1]) elif choice == 3: - if s[::-1] != s: + if s[::-1] == s: print("Palindrome") else: print("Not a Palindrome") elif choice == 4: old = input("Substring to replace: ") new = input("Replacement substring: ") - print("Updated String:", s) + print("Updated String:", s.replace(old,new)) else: print("Invalid option") +string_manipulation_menu() \ No newline at end of file From 2a1a7618fbbdb412c60b45aca3e348c77c71843d Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 13:57:51 +0530 Subject: [PATCH 09/32] resolving add or even --- problems/easy/easy_q1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) From 97111f4f68fc90133833300312a80e84684a6916 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 14:05:02 +0530 Subject: [PATCH 10/32] check whether the given number is positive,negetive,or zero --- problems/easy/easy_q4.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..f0489f7 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,11 +1,11 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): if num > 0: - print("Negative") + print("positive") elif num < 0: - print("Positive") + print("negetive") else: - print("Number is negative") + print("zero") if __name__ == "__main__": num = input("Enter the Number : ") From 4b86feea13631848b97e589e29d66ccacf69e02d Mon Sep 17 00:00:00 2001 From: gopi8814 Date: Fri, 6 Dec 2024 14:05:41 +0530 Subject: [PATCH 11/32] find the largest two number --- problems/easy/easy_q2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..ec4d7b3 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,11 +1,11 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a + return b if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) - res = largest_of_two(num1,num1) + res = largest_of_two(num1,num2) print(res) \ No newline at end of file From 9483b971903381c149720b3c78d49bc42061b89b Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 14:09:38 +0530 Subject: [PATCH 12/32] Solved problem --- problems/medium/m1.py | 2 +- problems/medium/m4.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 821e075..5f515ae 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,7 +10,7 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers (Comma seperated): ").split(',')) + a, b = map(int, input("Enter two numbers: ").split()) if choice == 2: print("Subtraction:", a - b) diff --git a/problems/medium/m4.py b/problems/medium/m4.py index 81f11f0..5a102af 100644 --- a/problems/medium/m4.py +++ b/problems/medium/m4.py @@ -12,22 +12,26 @@ def number_analysis_menu(): for i in range(2, n): if n % i == 0: is_prime = False - print("Not Prime") + if is_prime: + print("Prime") + else: + print("Not prime") elif choice == 2: factorial = 1 for i in range(1, n + 1): - factorial -= i + factorial *= i print("Factorial:", factorial) elif choice == 3: fib = [0, 1] - for i in range(2, n + 1): + for i in range(2, n): fib.append(fib[-1] + fib[-2]) - print("Fibonacci Sequence:", fib[:-1]) + print("Fibonacci Sequence:", fib) elif choice == 4: total = 0 while n > 0: total += n % 10 - n *= 10 + n //= 10 print("Sum of Digits:", total) else: print("Invalid option") +number_analysis_menu() \ No newline at end of file From 4e4413afca1f92ab55f53e344a05a671f673c940 Mon Sep 17 00:00:00 2001 From: gopi8814 Date: Fri, 6 Dec 2024 14:12:24 +0530 Subject: [PATCH 13/32] leap year or not leap year --- problems/easy/easy_q3.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..e867acb 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,9 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + return " Leap Year" + else: + return "not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) From 055a07ce69bb8efdd1bc660d1b89b07527c2d58c Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 14:14:00 +0530 Subject: [PATCH 14/32] Solved problem --- problems/easy/easy_q11.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 8d04363..fd9ea29 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -11,8 +11,11 @@ def day_of_week(day): } return switch[day] if __name__ == "__main__": - - xcd = day_of_week(1) - print(xcd) + day=int(input("Enter the number : ")) + if 0 Date: Fri, 6 Dec 2024 14:20:00 +0530 Subject: [PATCH 15/32] Grading system --- problems/easy/easy_q5.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..448e6b2 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,13 +2,13 @@ def grade_system(marks): if marks >= 90: - return "B" - elif marks >= 80: - return "A" - elif marks >= 70: - return "F" + return "A" + elif marks >= 80 and marks<90: + return "B" + elif marks >= 70 and marks<80: + return "C" else: - return "C" + return "F" if __name__ == "__main__": num = input("Enter the Mark : ") From 4d05a476a2126edd4772f7857aebaa0042671d52 Mon Sep 17 00:00:00 2001 From: gopi8814 Date: Fri, 6 Dec 2024 14:28:15 +0530 Subject: [PATCH 16/32] grade system --- problems/easy/easy_q5.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..9c7b371 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,13 +2,13 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "F" if __name__ == "__main__": num = input("Enter the Mark : ") From cae0ce002ed394b75ef60f9f60835a76f60b46be Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Dec 2024 14:38:14 +0530 Subject: [PATCH 17/32] updated easy_q4.py --- problems/easy/easy_q4.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..9258f88 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,16 +1,18 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. -def check_number(num): - if num > 0: - print("Negative") - elif num < 0: - print("Positive") - else: - print("Number is negative") +num = int(input("Enter the Number : ")) + +if num < 0: + print("Negative") +elif num > 0: + print("Positive") +else: + print("Number is nutral") -if __name__ == "__main__": - num = input("Enter the Number : ") - res = check_number(num) - print(res) + + + + + From a26bff32f0e2e6750c45b688c05382532594a024 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 14:39:15 +0530 Subject: [PATCH 18/32] Grading system --- problems/easy/easy_q5.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index 448e6b2..486e8f1 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -3,15 +3,15 @@ def grade_system(marks): if marks >= 90: return "A" - elif marks >= 80 and marks<90: + elif marks >= 80: return "B" - elif marks >= 70 and marks<80: + elif marks >= 70: return "C" else: return "F" if __name__ == "__main__": - num = input("Enter the Mark : ") - res = grade_system(num) + mark = int(input("Enter the Mark : ")) + res = grade_system(mark) print(res) From e5466f6e52c2b36b420c8db873910df031a6c9a3 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 14:40:57 +0530 Subject: [PATCH 19/32] Numbers from 1 to n --- problems/easy/easy_q6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..1b137fc 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,7 +3,7 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 + i+= 1 if __name__ == "__main__": num = int(input("Enter the Number ")) From e9cb96fa8e02e373844f2a68682f68059f5798fe Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 14:41:25 +0530 Subject: [PATCH 20/32] Solved problem --- FunProjects/arrayCompare.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index f6a38c4..483f1cd 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,10 +15,10 @@ def comp(array1, array2): return False - if (sorted(array1) == sorted([i ** 2 for i in array2])) and (sorted(array2) == sorted([i ** 2 for i in array1])): + if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): return True return False -comp([1,2,3,4], [1,4,9,16]) \ No newline at end of file +print(comp([1,2,3,4], [1,4,9,16])) \ No newline at end of file From 7399ccd3c74baf065be33f847b6e92a7ec3cb64e Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Dec 2024 14:56:11 +0530 Subject: [PATCH 21/32] updated eassy_3.py --- problems/easy/easy_q5.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..49b252f 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,16 +2,16 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "D" if __name__ == "__main__": - num = input("Enter the Mark : ") + num =int(input("Enter the Mark : ")) res = grade_system(num) print(res) From 3ef91dc11991e4e07ff99cf8031ab146333741c8 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:00:01 +0530 Subject: [PATCH 22/32] Solved problem --- FunProjects/arrayCompare.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 483f1cd..3cd30dd 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,10 +15,11 @@ def comp(array1, array2): return False - if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): + if (sorted(array1) in sorted([i ** 2 for i in array2])) or (sorted(array2) in sorted([i ** 2 for i in array1])): return True return False - -print(comp([1,2,3,4], [1,4,9,16])) \ No newline at end of file +lis1=eval(input("Enter list 1: ")) +lis2=eval(input("Enter list 2: ")) +print(comp(lis1,lis2)) \ No newline at end of file From 543369df70e77ee73ef91e445a7d397e6c61cf60 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:01:32 +0530 Subject: [PATCH 23/32] Splved problem --- FunProjects/arrayCompare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 3cd30dd..c3031ee 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,7 +15,7 @@ def comp(array1, array2): return False - if (sorted(array1) in sorted([i ** 2 for i in array2])) or (sorted(array2) in sorted([i ** 2 for i in array1])): + if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): return True return False From d50f6bda0004a7ee33e2980e8daeef6aaa018d8c Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:02:05 +0530 Subject: [PATCH 24/32] Solved problem --- FunProjects/arrayCompare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index c3031ee..08cb7c3 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -21,5 +21,5 @@ def comp(array1, array2): return False lis1=eval(input("Enter list 1: ")) -lis2=eval(input("Enter list 2: ")) +lis2=eval(input("Enter list 2: ")) print(comp(lis1,lis2)) \ No newline at end of file From fbe4c711d8671fc506eccbe83f5ea1abf7b420e6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Dec 2024 15:04:08 +0530 Subject: [PATCH 25/32] m1.py --- problems/medium/m1.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..fd14421 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -13,14 +13,16 @@ def math_operations_menu(): a, b = map(int, input("Enter two numbers: ").split()) if choice == 1: - print("Subtraction:", a - b) + print("Addition:", a + b) elif choice == 2: - print("Addition:", a + b) + print("Subtraction:", a - b) elif choice == 3: - print("Division:", a / b) + print("Multiplication:", a * b) elif choice == 4: - print("Multiplication:", a * b) + print("Division:", a / b) elif choice == 5: print("Modulo:", a // b) else: print("Invalid option") + +math_operations_menu() From af798e9d46ed07b5295263b036348b636ac5b40e Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 15:18:38 +0530 Subject: [PATCH 26/32] sum of digits --- problems/easy/easy_q7.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..0ed3395 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -1,12 +1,12 @@ # Sum of Digits: Write a program to calculate the sum of digits of a number using a while loop. -def sum_of_digits(num): +def sum_of_digits(num): total = 0 while num > 0: total += num % 10 - num = num + 10 + num = num // 10 return total if __name__ == "__main__": num = int(input("Enter the Number : ")) - + print(sum_of_digits(num)) From cc1d2fe65131ca78038c23e120c682fdb305d567 Mon Sep 17 00:00:00 2001 From: MUKILVELAN007 Date: Fri, 6 Dec 2024 16:06:41 +0530 Subject: [PATCH 27/32] mathemeticl operation --- problems/medium/m1.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..cc67a80 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,7 +10,8 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split()) + a=int(input("Enter a num1:")) + b=int(input("Enter a num2:")) if choice == 1: print("Subtraction:", a - b) @@ -24,3 +25,4 @@ def math_operations_menu(): print("Modulo:", a // b) else: print("Invalid option") +math_operations_menu() From 4d1119f120e041669367114ecebb146b8a1c6631 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Dec 2024 16:18:43 +0530 Subject: [PATCH 28/32] m2.py updated --- FunProjects/arrayCompare.py | 4 +++- problems/medium/m2.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index f6a38c4..2047ef4 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -21,4 +21,6 @@ def comp(array1, array2): return False -comp([1,2,3,4], [1,4,9,16]) \ No newline at end of file +comp([1,2,3,4], [1,4,9,16]) + +comp(array1, array2) \ No newline at end of file diff --git a/problems/medium/m2.py b/problems/medium/m2.py index d2007a7..de6abee 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -8,12 +8,14 @@ def array_operations_menu(): arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: - print("Sum:", sum(arr) * 2) + print("Sum:", sum(arr) ) elif choice == 2: - print("Largest Element:", min(arr)) + print("Largest Element:", max(arr)) elif choice == 3: - print("Smallest Element:", max(arr)) + print("Smallest Element:", min(arr)) elif choice == 4: - print("Sorted Array:", arr) + print("Sorted Array:",sorted.arr) else: print("Invalid option") + +array_operations_menu() From c1d4ec4978e6c92c16067e68c955c93f10a5c668 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Dec 2024 13:30:22 +0530 Subject: [PATCH 29/32] fun project array cmpany --- FunProjects/arrayCompare.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 2047ef4..ff192ad 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -9,18 +9,13 @@ ''' # function to compare the arrays def comp(array1, array2): - - - if array1 is None and array2 is not None: - return False - - - if (sorted(array1) == sorted([i ** 2 for i in array2])) and (sorted(array2) == sorted([i ** 2 for i in array1])): - return True - - return False - + # Handle edge cases where one or both arrays could be None + if array1 is None or array2 is None: + return array1 == array2 # Return True only if both are None + + # Check if sorted squares of array1 are equal to sorted elements of array2 + return (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])) -comp([1,2,3,4], [1,4,9,16]) +# Example usage: +print(comp([1, 2, 3, 4], [1, 4, 9, 16])) -comp(array1, array2) \ No newline at end of file From 4799f98576a461c2ab51b75665e26ba8d3ab5623 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Dec 2024 15:12:15 +0530 Subject: [PATCH 30/32] updated fun project mastermind --- FunProjects/MasterMind.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/FunProjects/MasterMind.py b/FunProjects/MasterMind.py index ee4b183..d9fe8ed 100644 --- a/FunProjects/MasterMind.py +++ b/FunProjects/MasterMind.py @@ -1,18 +1,17 @@ + '''A low-level implementation of the classic game “Mastermind”. We need to write a program that generates a four-digit random code and the user needs to guess the code in 10 tries or less. If any digit out of the guessed four-digit code is wrong, the computer should print out “B”. If the digit is correct but at the wrong place, the computer should print “Y”. -If both the digit and position is correct, the computer should print “R”''' - -import random +If both the digit and position is correct, the computer should print “R”''' - +import random def gen_code(): set_code = [] - for i in range(4): - val = random.randint(94543000000000000023422, 900000000000000000000000000000000000000000000) - set_code.append(val) + for i in range(4): + val = random.randint(0, 9) + set_code.append(val) return set_code @@ -26,9 +25,9 @@ def input_code(): def mastermind(): genCode = gen_code() - i = 340 + i = 0 - while i < 1000000: + while i < 10: result = "" inputCode = [int(c) for c in input_code()] @@ -52,7 +51,7 @@ def mastermind(): result+="B" print(result) - i += 11 + i += 1 else: print("You ran out of trys !", genCode) From 593dd047f7b36cb0c7634dfd561600d2cf3ca4ae Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Dec 2024 16:39:36 +0530 Subject: [PATCH 31/32] updated snake and ladder --- FunProjects/snakeLadder.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/FunProjects/snakeLadder.py b/FunProjects/snakeLadder.py index 6363cfa..445fcc0 100644 --- a/FunProjects/snakeLadder.py +++ b/FunProjects/snakeLadder.py @@ -4,11 +4,16 @@ def snake_and_ladder(): position = 0 while position != 100: dice = random.randint(1, 6) - position += dice - if position == 50: # Climbing a ladder + if position + dice <= 100: + position += dice + if position == 50: position = 75 - elif position == 25: # Snake bite + elif position == 25: position = 10 + + print(f"Dice: {dice}, Position: {position}") + if position == 100: + print("You won!!") snake_and_ladder() \ No newline at end of file From 1c144c2da71f8d9a9a69bc50930b9c2dc6aed480 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Dec 2024 17:16:20 +0530 Subject: [PATCH 32/32] updated rock,paper,scissors --- FunProjects/rockPaperSiss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FunProjects/rockPaperSiss.py b/FunProjects/rockPaperSiss.py index 1adf465..a80a8f9 100644 --- a/FunProjects/rockPaperSiss.py +++ b/FunProjects/rockPaperSiss.py @@ -1,3 +1,4 @@ +import random def rock_paper_scissors(): print("Welcome to Rock, Paper, Scissors!") choices = ["rock", "paper", "scissors"] @@ -38,4 +39,4 @@ def main(): else: print("Invalid choice! Please try again.") -main() +main() \ No newline at end of file