TheOnlygoose commited on
Commit
4a21946
·
verified ·
1 Parent(s): 7fe7223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -49
app.py CHANGED
@@ -1,51 +1,72 @@
1
- while True:
2
- print("Number Theory Calculator")
3
- print("1. Find GCD")
4
- print("2. Find LCM")
5
- print("3. Prime Factorization")
6
- print("4. Exit")
7
-
8
- choice = input("Choose an option (1-4): ")
9
-
10
- if choice == '1':
11
- a = int(input("Enter first number: "))
12
- b = int(input("Enter second number: "))
13
- while b != 0:
14
- a, b = b, a % b
15
- print("GCD is:", a)
16
-
17
- elif choice == '2':
18
- a = int(input("Enter first number: "))
19
- b = int(input("Enter second number: "))
20
- product = a * b
21
- x, y = a, b
22
- while y != 0:
23
- x, y = y, x % y
24
- lcm = product // x
25
- print("LCM is:", lcm)
26
-
27
- elif choice == '3':
28
- n = int(input("Enter a number: "))
29
- print("Prime factors are:", end=" ")
30
- d = 2
31
- while d * d <= n:
32
- while n % d == 0:
33
- print(d, end=" ")
34
- n = n // d
35
- d += 1
36
- if n > 1:
37
- print(n)
38
- else:
39
- print()
40
-
41
- elif choice == '4':
42
- print("Goodbye!")
43
-
44
  else:
45
- print("Invalid choice. Try again.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- rating = input("rate my project 1|10")
48
- if rating > "5":
49
- print("Thanks for the review")
50
- else:
51
- print("Please leave your share your issues on this Gmail annasrshd@gmail.com thank you")
 
1
+ import gradio as gr
2
+
3
+ def find_gcd(a, b):
4
+ x, y = a, b
5
+ while y != 0:
6
+ x, y = y, x % y
7
+ return f"GCD of {a} and {b} is {x}"
8
+
9
+ def find_lcm(a, b):
10
+ if a == 0 or b == 0:
11
+ return "LCM is 0"
12
+ product = a * b
13
+ x, y = a, b
14
+ while y != 0:
15
+ x, y = y, x % y
16
+ lcm = abs(product) // x
17
+ return f"LCM of {a} and {b} is {lcm}"
18
+
19
+ def prime_factors(n):
20
+ if n <= 1:
21
+ return "No prime factors for numbers <= 1"
22
+ factors = []
23
+ d = 2
24
+ while d * d <= n:
25
+ while n % d == 0:
26
+ factors.append(d)
27
+ n //= d
28
+ d += 1
29
+ if n > 1:
30
+ factors.append(n)
31
+ return f"Prime factors: {', '.join(map(str, factors))}"
32
+
33
+ def handle_rating(rating):
34
+ if int(rating) > 5:
35
+ return "Thanks for the review!"
 
 
 
 
 
 
 
 
36
  else:
37
+ return "Please share your issues at annasrshd@gmail.com. Thank you!"
38
+
39
+ # Create interfaces
40
+ gcd_interface = gr.Interface(
41
+ fn=find_gcd,
42
+ inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")],
43
+ outputs="text",
44
+ title="Find GCD"
45
+ )
46
+
47
+ lcm_interface = gr.Interface(
48
+ fn=find_lcm,
49
+ inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")],
50
+ outputs="text",
51
+ title="Find LCM"
52
+ )
53
+
54
+ prime_interface = gr.Interface(
55
+ fn=prime_factors,
56
+ inputs=gr.Number(label="Enter a Number"),
57
+ outputs="text",
58
+ title="Prime Factorization"
59
+ )
60
+
61
+ rating_interface = gr.Interface(
62
+ fn=handle_rating,
63
+ inputs=gr.Slider(1, 10, step=1, label="Rate the project (1 to 10)"),
64
+ outputs="text",
65
+ title="Project Feedback"
66
+ )
67
 
68
+ # Launch as tabs
69
+ gr.TabbedInterface(
70
+ [gcd_interface, lcm_interface, prime_interface, rating_interface],
71
+ ["GCD", "LCM", "Prime Factorization", "Feedback"]
72
+ ).launch()