Skip to content

Commit cdfa2a9

Browse files
Add files via upload
1 parent f8eab6e commit cdfa2a9

8 files changed

+198
-0
lines changed

Diff for: Milestone 2/Arrays & Lists/ArraySum.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Given an array of length N, you need to find and print the sum of all elements of the array.
2+
# Input Format :
3+
# Line 1 : An Integer N i.e. size of array
4+
# Line 2 : N integers which are elements of the array, separated by spaces
5+
6+
n=int(input())
7+
li=[int(x) for x in input().split()]
8+
sum=0
9+
for i in range(n):
10+
sum+=li[i]
11+
print(sum)

Diff for: Milestone 2/Functions/CheckArmstrong.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Write a Program to determine if the given number is Armstrong number or not.
2+
# Print true if number is armstrong, otherwise print false.
3+
# An Armstrong number is a number (with digits n) such that
4+
# the sum of its digits raised to nth power is equal to the number itself.
5+
# For example,
6+
# 371, as 3^3 + 7^3 + 1^3 = 371
7+
# 1634, as 1^4 + 6^4 + 3^4 + 4^4 = 1634
8+
9+
num = int(input())
10+
sum = 0
11+
n = num
12+
a = len(str(num))
13+
14+
while n != 0:
15+
r = n % 10
16+
sum = sum + r**a
17+
n = n // 10
18+
19+
if (sum == num):
20+
print('true')
21+
else:
22+
print('false')

Diff for: Milestone 2/Functions/FahrenheittoCelsiusFunction.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Given three values - Start Fahrenheit Value (S), End Fahrenheit value (E) and Step Size (W),
2+
# you need to convert all Fahrenheit values from Start to End at the gap of W,
3+
# into their corresponding Celsius values and print the table.
4+
# Input Format : 3 integers - S, E and W respectively
5+
6+
# Input :
7+
# 0
8+
# 100
9+
# 20
10+
# Output :
11+
# 0 -17
12+
# 20 -6
13+
# 40 4
14+
# 60 15
15+
# 80 26
16+
# 100 37
17+
18+
def printTable(start,end,step):
19+
while end >= start:
20+
c = (5*(start-32))/9
21+
d = int(c)
22+
print(start, d)
23+
start+=step
24+
25+
26+
s = int(input())
27+
e = int(input())
28+
step = int(input())
29+
printTable(s,e,step)

Diff for: Milestone 2/Functions/FibonacciMember.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Given a number N, figure out if it is a member of fibonacci series or not.
2+
# Return true if the number is member of fibonacci series else false.
3+
# Fibonacci Series is defined by the recurrence
4+
# F(n) = F(n-1) + F(n-2)
5+
# where F(0) = 0 and F(1) = 1
6+
7+
# Input 1 : 5
8+
# Output 1 : true
9+
# Input 2 : 14
10+
# Output 2 : false
11+
12+
13+
def checkMember(n):
14+
sum = 0
15+
a = 0
16+
b = 1
17+
N = n
18+
while n!=0:
19+
sum = a+b
20+
a = b
21+
b = sum
22+
n=n-1
23+
if sum == N:
24+
return True
25+
else:
26+
continue
27+
if sum == N:
28+
return True
29+
else:
30+
return False
31+
32+
33+
n = int(input())
34+
if(checkMember(n)):
35+
print("true")
36+
else:
37+
print("false")

Diff for: Milestone 2/Functions/Palindromenumber.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Write a program to determine if given number is palindrome or not.
2+
# Print true if it is palindrome, false otherwise.
3+
# Palindrome are the numbers for which reverse is exactly same as the original one. For eg. 121
4+
# Input : 121
5+
# Output : true
6+
7+
def checkPalindrome(num):
8+
n = num
9+
sum = 0
10+
while(n != 0):
11+
r = n % 10
12+
sum = sum*10+r
13+
n = n//10
14+
return sum
15+
16+
17+
num = int(input())
18+
isPalindrome = checkPalindrome(num)
19+
if(isPalindrome == num):
20+
print('true')
21+
else:
22+
print('false')

Diff for: Milestone 2/Test1/GreatestCommonDivisor.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# You are given two numbers, ‘X’ and ‘Y’.
2+
# Your task is to find the greatest common divisor of the given two numbers.
3+
# The Greatest Common Divisor of any two integers is the largest number that divides both integers.
4+
5+
# Input :
6+
# 2
7+
# 20 15
8+
# 8 32
9+
# Output :
10+
# 5
11+
# 8
12+
13+
def findGcd(x, y):
14+
while y:
15+
x, y = y, x % y
16+
return x
17+
18+
t=int(input())
19+
while t!=0:
20+
x,y=input().split()
21+
x,y=int(x),int(y)
22+
print(findGcd(x,y))
23+
t=t-1

Diff for: Milestone 2/Test1/NumberStarpattern1.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n = int(input())
2+
i = 1
3+
k = 1
4+
while i<= n:
5+
j= n
6+
while j>= 1:
7+
if j==k:
8+
print('*',end='')
9+
else:
10+
print(j,end='')
11+
j=j-1
12+
print()
13+
i=i+1
14+
k=k+1
15+

Diff for: Milestone 2/Test1/YetanotherPattern.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Ninja was playing with her sister to solve a puzzle pattern. However,
2+
# even after taking several hours, they could not solve the problem.
3+
# A value of N is given to them, and they are asked to solve the problem.
4+
# Since they are stuck for a while, they ask you to solve the problem.
5+
# Can you help solve this problem?
6+
7+
# Input :
8+
# 2
9+
# 3
10+
# 2
11+
# Output :
12+
# ***
13+
# **
14+
# *
15+
16+
# **
17+
# *
18+
19+
20+
def ninjaPuzzle(n):
21+
i=1
22+
while i<=n:
23+
sp=1
24+
while sp<i:
25+
print(' ',end='')
26+
sp=sp+1
27+
j=1
28+
while j<=n-i+1:
29+
print('*',end='')
30+
j=j+1
31+
print()
32+
i=i+1
33+
return 0
34+
35+
t=int(input())
36+
while t !=0 :
37+
n = int(input())
38+
ninjaPuzzle(n)
39+
t=t-1

0 commit comments

Comments
 (0)