diff --git a/FunProjects/todoApp.py b/FunProjects/todoApp.py index 3feba70..407608b 100644 --- a/FunProjects/todoApp.py +++ b/FunProjects/todoApp.py @@ -7,12 +7,19 @@ def add_task(self, task): print(f"Task '{task}' added.") def remove_task(self, task): - self.tasks.remove(task) - print(f"Task '{task}' removed.") + if task in self.tasks: + self.tasks.remove(task) + print(f"Task '{task}' removed.") + else: + print(f"task'{task}'not found in the list") def display_tasks(self): - for task in self.tasks: - print(f"- {task}") + if self.tasks: + print("your task:") + for task in self.tasks: + print(f"- {task}") + else: + print("no task in the list") todo = TodoList() diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index a48fece..d8c229c 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -3,8 +3,16 @@ num = int(input("Enter a number: ")) +if (num % 2) != 0: + print("{0} is Odd".format(num)) +else: + + if (num % 2) == 0: + + print("{0} is Even".format(num)) else: print("{0} is Odd".format(num)) - \ No newline at end of file + + \ No newline at end of file diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 3ad440b..b052934 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -3,10 +3,29 @@ def is_palindrome(num): original = num reverse = 0 + + while True: + reverse = reverse * 10 + num % 10 + num //= 10 + if num == 0: + break + return reverse == original + + + + while True: + reverse = reverse * 10 + num % 10 + num //= 10 + if num != 0: + break + while num != 0: reverse = reverse * 10 + num % 10 num //= 10 + + + return reverse == original reverse = '' @@ -18,9 +37,13 @@ def is_palindrome(num): else: return "It is not a Palindrome" + if __name__ == "__main__": nums = int(input("Enter the Number: ")) res = is_palindrome(nums) print(res) - - + + + + + diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 182540b..86d704f 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -1,4 +1,4 @@ -# Day of the Week: Write a program that takes a number (1-7) and prints the corresponding day of the week using a switch case. +# def day_of_week(day): switch = { 1: "Monday", @@ -9,6 +9,26 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } + + if day <=7 : + return switch[8] + else: + print("Error occured") +if __name__ == "__main__": + day = int(input("Enter a number (1-7) to get the day of the week: ")) + result = day_of_week(day) + print(result) + + + if day < 1 or day > 7: + return "Invalid day" + return switch[day] +if __name__ == "__main__": + xcd = day_of_week(32) + print(xcd) + + + return switch[day] if __name__ == "__main__": @@ -25,5 +45,4 @@ def day_of_week(day): print(xcd) else: print("Enter Valid Input") - - + \ No newline at end of file diff --git a/problems/easy/easy_q12.py b/problems/easy/easy_q12.py index 1a02b99..c762cae 100644 --- a/problems/easy/easy_q12.py +++ b/problems/easy/easy_q12.py @@ -13,7 +13,11 @@ def calculator(a, b, operator): n2 = int(input("Enter the Number 2 :")) opr = input("Enter the Operator :") result = calculator(n1,n2,opr) + + print(result) + print(result) + print(result) \ No newline at end of file diff --git a/problems/easy/easy_q13.py b/problems/easy/easy_q13.py index 24e98a6..90d0a0c 100644 --- a/problems/easy/easy_q13.py +++ b/problems/easy/easy_q13.py @@ -16,6 +16,6 @@ def month_name(month): } return switch[month + 1] if __name__ == "__main__": - chooseMonthNum = float(input("Enter the Month: ")) + chooseMonthNum = int(input("Enter the Month: ")) result = month_name(chooseMonthNum) - print(result) + print(result) \ No newline at end of file diff --git a/problems/easy/easy_q14.py b/problems/easy/easy_q14.py index eae63b0..10153a9 100644 --- a/problems/easy/easy_q14.py +++ b/problems/easy/easy_q14.py @@ -7,8 +7,11 @@ def vowel_or_consonant(char): 'o': "Vowel", 'u': "Vowel", } - return switch.get(char, "Vowel") + return switch.get(char.lower(),"Constant") if __name__ == "__main__": - characterInput = int(input("Enter the charactrer : ")) - res = vowel_or_consonant(characterInput) - print(res) + characterInput = input("Enter the charactrer : ") + if len(characterInput)==1: + res = vowel_or_consonant(characterInput) + print(res) + else: + print("Please enter exactly one character.") \ No newline at end of file diff --git a/problems/easy/easy_q15.py b/problems/easy/easy_q15.py index 2868314..c13c8bf 100644 --- a/problems/easy/easy_q15.py +++ b/problems/easy/easy_q15.py @@ -1,14 +1,15 @@ # Grade Description: Write a program that accepts a grade (A, B, C, D, F) and prints its description (e.g., A = Excellent, B = Good, etc.) using a switch case. def grade_description(grade): switch = { - 'A': "Good", - 'B': "Average", - 'C': "Poor", - 'D': "Excellent", + 'A': "Excellent", + 'B': "Good", + 'C': "Average", + 'D': "Poor", 'F': "Fail" } - return switch.get(grade, "Not a valid grade") + return switch.get(grade.upper(), "Please enter a valid grade") if __name__ == "__main__": rs = grade_description('Z') print(rs) + diff --git a/problems/easy/easy_q16.py b/problems/easy/easy_q16.py index b810a85..16b00c5 100644 --- a/problems/easy/easy_q16.py +++ b/problems/easy/easy_q16.py @@ -1,6 +1,15 @@ # Print the Sum of First and Last Array Element def sum_first_last(arr): - return arr[1] + arr[-1] + return arr[0] + arr[-1] if __name__ == "__main__": # Handle the input by Yourself - sum_first_last() \ No newline at end of file + + arr=[] + n=int(input("Enter the Total number of Elements:")) + for i in range(n): + x=int(input("Enter the element :")) + arr.append(x) + + arr=[2,5,8,7,6] + + print(sum_first_last(arr)) \ No newline at end of file diff --git a/problems/easy/easy_q17.py b/problems/easy/easy_q17.py index 7a5356c..ac3dffa 100644 --- a/problems/easy/easy_q17.py +++ b/problems/easy/easy_q17.py @@ -1,7 +1,13 @@ # Print X N Times -def print_x_n_times(x, n): - for i in range(1, n): # Bug: Loop runs one less time than expected - print(x) +def print_x_n_times(x, n): # Bug: Loop runs one less time than expected + print(x*n) if __name__ == "__main__": # Handle the input by Yourself - print_x_n_times() \ No newline at end of file + + n=int(input("Enter the number of times:")) + x="X" + + x=input("Enter a character:") + n=int(input("enter the number of times to loop:")) + + print_x_n_times(x,n) \ No newline at end of file diff --git a/problems/easy/easy_q18.py b/problems/easy/easy_q18.py index abfc1ea..ba8b693 100644 --- a/problems/easy/easy_q18.py +++ b/problems/easy/easy_q18.py @@ -1,6 +1,12 @@ # Print Last Character of String def last_char_of_string(s): - return s[-2] # Bug: Fetches second-to-last character instead of last + return s[-1] # Bug: Fetches second-to-last character instead of last if __name__ == "__main__": # Handle the input by Yourself - last_char_of_string() \ No newline at end of file + + s=input("Enter the string:") + print(last_char_of_string(s)) + + s=[7,8,9,6] + print( last_char_of_string(s)) + diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index ff47888..15ff2ec 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -3,16 +3,37 @@ def largest_of_two(a, b): if a > b: + return a + + return a + else: return b +if __name__=="__main__": + a = int(input("Enter the First Number :")) + b = int(input("Enter the Second Number :")) + res = largest_of_two(a,b) + print(res) + + + return a + + return b + + return a + else: + return b + + + if __name__ == "__main__": num1 = int(input("Enter the First Number :")) - num2 = int(input("Enter the Second Number :")) + num2 = int(input("Enter the Second :")) res = largest_of_two(num1,num2) + print(res) + + - print(num1,"larger") - else: - print(num2,"larger") \ No newline at end of file diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index ef1d387..dda11f9 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -2,24 +2,15 @@ def is_leap_year(year): - if year % 4 == 0: - if year % 100 == 0: - return "Not a Leap Year" - if year % 400 == 0: - return "Leap Year" - return "Leap Year" - - if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - + if year % 4 != 0 and year % 100 == 0 or year % 400 != 0: + return "Not a Leap Year" + else: + return "Leap Year" - return "Leap Year" - return "Not a Leap Year" - return " Leap Year" + if year % 4 == 0 or year % 100 == 0 or year % 400 == 0: + return "Leap Year" else: - return "not a Leap Year" - + return "Not a Leap Year" - return "Leap Year" - return "Not a Leap Year" - \ No newline at end of file + \ No newline at end of file diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index b99ff2e..3ebca2a 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -4,19 +4,18 @@ def check_number(num): - if num < 0: - print("Negative") - elif num > 0: - print("Positive") - else: - - print("Number is Zero") + print("The given number is Negative" if (num < 0 ) else "The given number is Positive" if (num > 0) else "The given number is Zero") if __name__ == "__main__": num = int(input("Enter the Number : ")) check_number(num) + + if num > 0: + print("positive") + elif num < 0: + print("negative") + else: print("Number is zero") - - + diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index 7ada51f..2439bfb 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -1,6 +1,19 @@ -# Grading System: Write a program that takes a student’s marks as input and prints the grade (A, B, C, or F) based on given thresholds. - def grade_system(marks): + + if marks >=90 and marks <=100: + return "A" + elif marks >= 80 and marks <=90: + return "B" + elif marks >= 70 and marks <=80: + return "C" + else: + return "D" + +if __name__ == "__main__": + num = int(input("Enter the Mark : ")) + res = grade_system(num) + print(res) + if marks >= 90: return "A" elif marks >= 80: @@ -9,7 +22,15 @@ def grade_system(marks): return "C" else: + return "F" + + + return "D" + + return "F" + + if __name__ == "__main__": mark = int(input("Enter the Mark : ")) @@ -22,4 +43,4 @@ def grade_system(marks): if __name__ == "__main__": num = int(input("Enter the Mark : ")) res = grade_system(num) - \ No newline at end of file + diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index cc53209..c24e85d 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -4,11 +4,10 @@ def print_numbers(n): while i <= n: print(i) -if __name__ == "__main__": - num = int(input("Enter the Number ")) - print_numbers(num) - - num = int(input("Enter the Number :")) + i += 1 + +if __name__ == "__main__": + num = int(input("Enter the Number ")) print_numbers(num) - + \ No newline at end of file diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index eccd1cd..0a56164 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -1,26 +1,25 @@ -# Sum of Digits: Write a program to calculate the sum of digits of a number using a while loop. -def sum_of_digits(num): - total = 0 - while num > 0: - total += num % 10 - - num = num // 10 - - - num = num // 10 - num //= 10 +def sum_of_digits(num): + total = 0 + while num > 0: + total += num % 10 + num //= 10 return total if __name__ == "__main__": - num = int(input("Enter the Number : ")) - - res=sum_of_digits(num) - print(res) + num = int(input("Enter the Number: ")) + if num < 0: + num = -num + result = sum_of_digits(num) + print(f"Sum of digits: {result}") + - + total += num % 10 + num = num//10 - + + return total + \ No newline at end of file diff --git a/problems/easy/easy_q8.py b/problems/easy/easy_q8.py index 526f5ab..9f8aa51 100644 --- a/problems/easy/easy_q8.py +++ b/problems/easy/easy_q8.py @@ -1,13 +1,28 @@ # Reverse a Number: Accept a number and print its reverse using a while loop. def reverse_number(num): + + rev = "" + while num != 0: + digit = num % 10 #digit = 123%10 = 3 12%10 + rev = rev + str(digit) #rev = 3 + num //= 10 # num//= 10 = 12 + return rev + rev = '' while num != 0: digit = num % 10 + + rev = rev*10+ digit + num //= 10 + return rev + rev = rev + str(digit) num //= 10 return int(rev) + + if __name__ == "__main__": - num = int(input("Enter num : ")) + num = int(input("Enter num : ")) #123 res = reverse_number(num) print(res) diff --git a/problems/easy/easy_q9.py b/problems/easy/easy_q9.py index df9a503..2c82f2e 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -1,16 +1,32 @@ # Factorial of a Number: Write a program to calculate the factorial of a given number using a while loop. def factorial(n): result = 1 + + i=1 + while i <= n: + result *= i + i += 1 + while n > 0: result *= n n -= 1 + return result if __name__ == "__main__": + + n= int(input("Enter the Number :")) + print(factorial(n)) + + num = int(input("Enter the Number :")) print(factorial(num)) - + + + print(factorial(num)) + + res=factorial(num) print(res) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 99456d9..03d0867 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -1,8 +1,32 @@ -''' -Create a menu to perform basic mathematical operations (addition, subtraction, multiplication, division, modulo) on two numbers. - -''' def math_operations_menu(choice): + + try: + a, b = map(int, input("Enter two numbers (separated by a comma): ").split(sep=",")) + + # Perform the operation based on user's choice + if choice == 1: + print(f"Addition of {a} and {b}: {a + b}") + elif choice == 2: + print(f"Subtraction of {a} and {b}: {a - b}") + elif choice == 3: + print(f"Multiplication of {a} and {b}: {a * b}") + elif choice == 4: + if b == 0: + print("Error! Division by zero is not allowed.") + else: + print(f"Division of {a} and {b}: {a / b}") + elif choice == 5: + if b == 0: + print("Error! Modulo by zero is not allowed.") + else: + print(f"Modulus of {a} and {b}: {a % b}") + elif choice == 6: + print(f"{a} to the power of {b}: {a ** b}") + else: + print("Invalid option!!!") + except ValueError: + print("Invalid input! Please enter two valid numbers separated by a comma.") + a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) @@ -25,4 +49,5 @@ def math_operations_menu(choice): print("Invalid option") math_operations_menu() - \ No newline at end of file + + diff --git a/problems/medium/m10.py b/problems/medium/m10.py index 89f6b41..8cfcd14 100644 --- a/problems/medium/m10.py +++ b/problems/medium/m10.py @@ -2,7 +2,7 @@ def game_menu(): while True: - print("\n1. Number Guessing Game") + print("1. Number Guessing Game") print("2. Rock-Paper-Scissors") print("3. Dice Roll Simulation") print("4. Exit") @@ -11,7 +11,11 @@ def game_menu(): if choice == 1: target = random.randint(1, 100) guess = int(input("Guess a number between 1 and 100: ")) + + if guess = target: + if guess == target: + print("You won!") else: print("Try Again") @@ -31,5 +35,16 @@ def game_menu(): break else: print("Invalid Choice") + +game_menu() + + +x=input("Can we play some games?? (type yes and no)") +if x=="yes": + game_menu() +else: + print("Okey , let's play later!") + -game_menu() \ No newline at end of file +game_menu() + \ No newline at end of file diff --git a/problems/medium/m11.py b/problems/medium/m11.py index a6422c7..0429420 100644 --- a/problems/medium/m11.py +++ b/problems/medium/m11.py @@ -1,38 +1,51 @@ # Menu driven program to calculate perimeter and area of different shapes def per_circle(radius): + perimeter = 3.14 * radius - print("Perimeter of Circle: ", perimeters) + print("Perimeter of Circle: ", perimeter) def per_triangle(side1, side2, side3): - perimeter = side1 + side3 + perimeter = side1 + side2 + side3 + + perimeter =2* 3.14 * radius + print("Perimeter of Circle: ", perimeter) + +def per_triangle(side1, side2, side3): + perimeter = side1 + side2+ side3 + print("Perimeter of Triangle: ", perimeter) def per_rectangle(height, width): - perimeter = (height + width) - print("Perimeter of Rectangle: ", perimeters) + perimeter = 2*(height + width) + print("Perimeter of Rectangle: ", perimeter) def per_square(side): - perimeter = side * 3 + perimeter = side * 4 print("Perimeter of Square: ", perimeter) def a_circle(radius): - area = 3.14 * radius ** 2 - print("Area of Circle: ", areas) + area = 3.14 * (radius ** 2) + print("Area of Circle: ", area) def a_triangle(base, height): - area = base * height + area = 0.5 (base * height) print("Area of Triangle: ", area) def a_rectangle(height, width): - area = height + width + area = height * width print("Area of Rectangle: ", area) def a_square(side): - area = side * 3 + + area = side * side + + area = side *2 + print("Area of Square: ", area) - + + print("\nWELCOME TO MENSURATION PROGRAM! TRY CALCULATING PERIMETER AND AREA OF DIFFERENT GEOMETRIC SHAPES.") @@ -53,10 +66,10 @@ def a_square(side): choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: radius = float(input("Enter Radius of Circle: ")) - per_circles(radius) + per_circle(radius) elif choice1 == 2: radius = float(input("Enter Radius of Circle: ")) - a_circle() + a_circle(radius) elif choice1 == 3: break else: @@ -69,13 +82,20 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: + side1 = int(input("Enter length of side1: ")) side2 = int(input("Enter length of side2: ")) side3 = int(input("Enter length of side3: ")) - per_triangle(side1, side2) + per_triangle(side1, side2, side3) + + side1 = float(input("Enter length of side1: ")) + side2 = float(input("Enter length of side2: ")) + side3 = float(input("Enter length of side3: ")) + per_triangle(side1,side2,side3) + elif choice1 == 2: base = float(input("Enter base of triangle: ")) - height = input("Enter height of triangle: ") + height = float(input("Enter height of triangle: ")) a_triangle(base, height) elif choice1 == 3: break @@ -89,12 +109,18 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: + height = int(input("Enter height of rectangle: ")) - per_rectangle(height) + width = int(input("Enter width of rectangle: ")) + + height = float(input("Enter height of rectangle: ")) + width = float(input("Enter width of rectangle: ")) + + per_rectangle(height,width) elif choice1 == 2: height = float(input("Enter height of rectangle: ")) width = int(input("Enter width of rectangle: ")) - a_rectangle(height) + a_rectangle(height,width) elif choice1 == 3: break else: @@ -107,10 +133,10 @@ def a_square(side): print("3. Exit") choice1 = int(input("\nEnter choice for calculations: ")) if choice1 == 1: - side = int(input("Enter side of square: ")) + side = float(input("Enter side of square: ")) per_square(side) elif choice1 == 2: - side = input("Enter side of square: ") + side = int(input("Enter side of square: ")) a_square(side) elif choice1 == 3: break diff --git a/problems/medium/m13.py b/problems/medium/m13.py index 33dfa3f..5751959 100644 --- a/problems/medium/m13.py +++ b/problems/medium/m13.py @@ -9,7 +9,16 @@ def is_prime(num): return False return True -n = int(input("Enter a number: ")) -for i in range(2, n + 1): - if is_prime(i): - print(i) +while True: + try: + n = int(input("Enter a number: ")) + break + except: + print("Enter valid a integer.") + + +if is_prime(n): + print(f"{n} is a prime number.") +else: + print(f"{n} is not a prime number.") + \ No newline at end of file diff --git a/problems/medium/m15.py b/problems/medium/m15.py index ab58cd0..afcb2e3 100644 --- a/problems/medium/m15.py +++ b/problems/medium/m15.py @@ -1,30 +1,16 @@ '''Write a program to check if a number is an Armstrong number (e.g., 153 = 1^3 + 5^3 + 3^3 ) .''' -def count_digits(n): - i = 0 - while n > 0: - n //= 10 - i += 1 - return i +a=input("Enter Number:") +def Arms(a): + e=0 + for i in a: + c=int(i) + d=c*c*c + e+=d + return e -def sum(n): - i = count_digits(n) - s = 0 - temp=n - while temp > 0: - digit = temp%10 - temp//= 10 - s += pow(digit,i) - return s - - -num = 1634 - - -s = sum(num) - - -if s == num: - print('Given number is an Armstrong Number') +b=Arms(a) +f=int(a) +if b==f: + print(b,"is an Armstrong Number") else: - print('Given number is not an Armstrong Number') - + print(b,"is not An Armstrong Number") \ No newline at end of file diff --git a/problems/medium/m17.py b/problems/medium/m17.py index e857a27..c554451 100644 --- a/problems/medium/m17.py +++ b/problems/medium/m17.py @@ -1,16 +1,16 @@ '''Write a program to reverse a given list without using built-in functions''' def reverse_list(lst): - start = -1 - end = -len(lst) - - - while start > end: - + + return lst[::-1] +lst=[1,2,3,4,5] +print(reverse_list(lst)) + + start = 0 + end = len(lst)-1 + while start < end: lst[start], lst[end] = lst[end], lst[start] - - - start -= 1 - end += 1 + start += 1 + end -= 1 return lst @@ -18,4 +18,5 @@ def reverse_list(lst): print("Original list:", input_list) reversed_list = reverse_list(input_list) -print("Reversed list:", reversed_list) \ No newline at end of file +print("Reversed list:", reversed_list) + \ No newline at end of file diff --git a/problems/medium/m2.py b/problems/medium/m2.py index 56d86bd..a35be12 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -3,8 +3,10 @@ def array_operations_menu(): print("2. Largest Element") print("3. Smallest Element") print("4. Sort Array") + choice = int(input("Enter your choice: ")) + arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: @@ -19,10 +21,17 @@ def array_operations_menu(): print("Smallest Element:", min(arr)) elif choice == 4: + + arr.sort() # sorts the array in ascending order by default + print("Sorted Array:", arr) + else: + print("Invalid option") + print("Sorted Array:",sorted.arr) else: print("Invalid option") + array_operations_menu() arr.sort() @@ -36,6 +45,4 @@ def array_operations_menu(): else: print("Invalid option") array_operations_menu() - - - + \ No newline at end of file diff --git a/problems/medium/m3.py b/problems/medium/m3.py index 5d5d7b8..045664c 100644 --- a/problems/medium/m3.py +++ b/problems/medium/m3.py @@ -24,7 +24,12 @@ def string_manipulation_menu(): elif choice == 4: old = input("Substring to replace: ") new = input("Replacement substring: ") + + s = s.replace(old, new) + print("Updated String:", s) + print("Updated String:", s.replace(old,new)) + else: print("Invalid option") string_manipulation_menu() \ No newline at end of file diff --git a/problems/medium/m8.py b/problems/medium/m8.py index 89c7cb1..c3981fc 100644 --- a/problems/medium/m8.py +++ b/problems/medium/m8.py @@ -9,7 +9,7 @@ def conversion_menu(): if choice == 1: celsius = int(input("Enter temperature in Celsius: ")) - fahrenheit = (celsius * 9 / 5) + 32 + fahrenheit = (celsius * 5 / 9) + 32 print("Temperature in Fahrenheit:", fahrenheit) elif choice == 2: fahrenheit = int(input("Enter temperature in Fahrenheit: ")) @@ -17,14 +17,19 @@ def conversion_menu(): print("Temperature in Celsius:", celsius) elif choice == 3: decimal = int(input("Enter a decimal number: ")) - print(f"Binary: {bin(decimal)}, Octal: {oct(decimal)}, Hexadecimal: {hex(decimal)}") + print(f"Binary: {bin(decimal)}, Octal: {oct(decimal):O}, Hexadecimal: {hex(decimal):X}") elif choice == 4: - km = float(input("Enter distance in kilometers: ")) - miles = km * 0.621371 - print("Distance in Miles:", miles) + selection = int(input("Enter 1 for KM to Miles (or) 2 for Miles to KM : ")) + if selection == 1: + km = float(input("Enter distance in kilometers: ")) + miles = km / 0.621371 + print("Distance in Miles:", miles) + else: + miles = float(input("Enter distance in miles :")) + km = miles * 1.609 + print("Distance in Kilometres:", km) elif choice == 5: print("Exiting...") break else: print("Invalid Choice") -conversion_menu() \ No newline at end of file