Computer Science, asked by hoodacruze, 4 months ago

Write Python Programs to :
a) find GCD of a number
c) Show details of 5 employes.
d)Print fibonacci series
e) Check Palindrome.
b) show series 1/1+1/2+1/3+1/4_,___1/n​​

Answers

Answered by himanshu2006vps
1

Answer:

a)def gcd(a,b):

if(b==0):

return a

else:

return gcd(b,a%b)

a=int(input("Enter first number:"))

b=int(input("Enter second number:"))

GCD=gcd(a,b)

print("GCD is: ")

print(GCD)

b)n=int(input("Enter the number of terms: "))

sum1=0

for i in range(1,n+1):

sum1=sum1+(1/i)

print("The sum of series is",round(sum1,2))

d)# Program to display the Fibonacci sequence up to n-th term

nterms = int(input("How many terms? "))

# first two terms

n1, n2 = 0, 1

count = 0

# check if the number of terms is valid

if nterms <= 0:

print("Please enter a positive integer")

elif nterms == 1:

print("Fibonacci sequence upto",nterms,":")

print(n1)

else:

print("Fibonacci sequence:")

while count < nterms:

print(n1)

nth = n1 + n2

# update values

n1 = n2

n2 = nth

count += 1

e)# function which return reverse of a string

def isPalindrome(s):

return s == s[::-1]

# Driver code

s = "malayalam"

ans = isPalindrome(s)

if ans:

print("Yes")

else:

print("No")

cimport random

class Bank:

def __init__(self):

self.dic={}

self.acctno=random.randrange(10000,100000,1)

def newAccount(self):

print("Enter your name")

self.name=input()

self.dic[self.name]={}

print("Enter the initial deposite ")

self.initAmount=int(input())

self.dic[self.name][self.acctno]=self.initAmount

def display(self):

print("Account creation has been successful. Your account number is ",self.acctno)

print()

print()

def existing(self,nam,actno):

self.nam=nam

self.actno=actno

if self.dic[self.nam][self.actno] >=0:

print("Authentication Successfull")

print()

return True

else:

print("Authentication Failed")

print()

return False

def withdrawal(self,nam,actno):

print("Enter a withdrawal amount ")

self.wit=int(input())

self.nam=nam

self.actno=actno

if self.dic[self.nam][self.actno]>=self.wit:

self.dic[self.nam][self.actno]=self.dic[self.nam][self.actno]-self.wit

print("Withdrawal was successful.")

print("Available balance : ",self.dic[self.nam][self.actno])

print()

else:

print("Insufficient balance ")

print()

def addamount(self,nam,actno):

self.nam=nam

self.actno=actno

print("Enter the amount you want to deposite ")

self.add=int(input())

print()

self.dic[self.nam][self.actno]=self.dic[self.nam][self.actno]+self.add

print("Deposite was successful.")

print("Available balance ",self.dic[self.nam][self.actno])

def displaybalance(self,nam,actno):

self.nam=nam

self.actno=actno

print("Available balance ",self.dic[self.nam][self.actno])

bank=Bank()

while True:

print("Enter 1 to create a new account ")

print("Enter 2 to access Existing account ")

print("Enter 3 to exit ")

userchoice=int(input())

if userchoice==1:

newaccount=bank.newAccount()

bank.display()

elif userchoice==2:

print("Enter your name ")

nam=input()

print("Enter your account number")

actno=int(input())

boolean=bank.existing(nam,actno)

if boolean:

while True:

print("Enter 1 to withdraw ")

print("Enter 2 to deposite ")

print("Enter 3 to display available balance ")

print("Enter 4 to go back to the previous menu ")

userinput=int(input())

if userinput==1:

bank.withdrawal(nam,actno)

elif userinput==2:

bank.addamount(nam,actno)

elif userinput==3:

bank.displaybalance(nam,actno)

elif userinput==4:

break

else:

continue

elif userchoice==3:

exit()

Similar questions