Skip to content

Commit c55ac78

Browse files
AmanxUpadhyaytechyminati
authored andcommitted
Trick yet simple questions
1 parent d8cf3e8 commit c55ac78

File tree

10 files changed

+194
-0
lines changed

10 files changed

+194
-0
lines changed

Tricky_Questions/Question_1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program for finding biggest of three numbers.
8+
def Biggest(a, b, c):
9+
if a > b and a > c:
10+
return a
11+
elif b > a and b > c:
12+
return b
13+
else:
14+
return c
15+
16+
17+
# Driver code
18+
x, y, z = [int(x) for x in input("Enter three numbers: ").split()]
19+
print("Biggest number is: ", Biggest(x, y, z))

Tricky_Questions/Question_10.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to generate n-th Fibonacci number.
8+
def Fibonacci(n):
9+
a = 0
10+
b = 1
11+
i = 0
12+
while i < n:
13+
print(a)
14+
a, b = b, a + b
15+
i += 1
16+
17+
# Driver code
18+
Number = int(input("Enter a number: "))
19+
Fibonacci(Number)

Tricky_Questions/Question_2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program using loop to print the decimal equivalents of 1/2, 1/3, 1/4 ,....... 1/n
8+
def decimal(n):
9+
i = 1
10+
while i <= n:
11+
print(1 / i)
12+
i += 1
13+
14+
# Driver code
15+
Number = int(input("Enter a number: "))
16+
decimal(Number)

Tricky_Questions/Question_3.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program for displaying reversal of a number n.
8+
def reverse(n):
9+
rev = 0
10+
while n > 0:
11+
dig = n % 10
12+
rev = rev * 10 + dig
13+
n = n // 10
14+
return rev
15+
16+
# Driver code
17+
n = int(input("Enter a number: "))
18+
print("Reverse of the number is: ", reverse(n))

Tricky_Questions/Question_4.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to generate first N natural numbers.
8+
def NaturalNumber(n):
9+
i = 1
10+
while i <= n:
11+
print(i)
12+
i += 1
13+
14+
# Driver code
15+
Number = int(input("Enter a number: "))
16+
NaturalNumber(Number)

Tricky_Questions/Question_5.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to check given number is palindrome or not.
8+
def PalindromeCheck(n):
9+
rev = 0
10+
while n > 0:
11+
dig = n % 10
12+
rev = rev * 10 + dig
13+
n = n // 10
14+
if rev == n:
15+
return True
16+
else:
17+
return False
18+
19+
# Driver code
20+
n = int(input("Enter a number: "))
21+
if PalindromeCheck(n):
22+
print("Number is palindrome")
23+
else:
24+
print("Number is not palindrome")

Tricky_Questions/Question_6.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to print factorial of a number.
8+
def Factorial(n):
9+
fact = 1
10+
while n > 0:
11+
fact = fact * n
12+
n -= 1
13+
return fact
14+
15+
# Driver code
16+
Number = int(input("Enter a number: "))
17+
print("Factorial of the number is: ", Factorial(Number))

Tricky_Questions/Question_7.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to print sum of N natural numbers.
8+
def NaturalNumber(n):
9+
i = 1
10+
sum = 0
11+
while i <= n:
12+
sum = sum + i
13+
i += 1
14+
return sum
15+
16+
# Driver code
17+
Number = int(input("Enter a number: "))
18+
print("Sum of the number is: ", NaturalNumber(Number))

Tricky_Questions/Question_8.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to check given number is Armstrong or not.
8+
def ArmstrongCheck(n):
9+
sum = 0
10+
temp = n
11+
while temp > 0:
12+
digit = temp % 10
13+
sum += digit ** 3
14+
temp //= 10
15+
if sum == n:
16+
return True
17+
else:
18+
return False
19+
20+
# Driver code
21+
n = int(input("Enter a number: "))
22+
if ArmstrongCheck(n):
23+
print("Number is Armstrong")
24+
else:
25+
print("Number is not Armstrong")

Tricky_Questions/Question_9.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# * Author: Aman Upadhyay
3+
# * Email: amanupadhyay0208@gmail.com
4+
# * GitHub: https://github.com/AmanxUpadhyay
5+
#
6+
7+
# Write a Python program to generate prime numbers of series up to n.
8+
def PrimeNumber(n):
9+
i = 2
10+
while i <= n:
11+
j = 2
12+
while j <= (i // 2):
13+
if i % j == 0:
14+
break
15+
j += 1
16+
else:
17+
print(i)
18+
i += 1
19+
20+
# Driver code
21+
Number = int(input("Enter a number: "))
22+
PrimeNumber(Number)

0 commit comments

Comments
 (0)