Practice Problems 6 Fall 17
1) Elizabeth visits her friend Andrew and then returns home by the same route. She always walks 2 kilometers per hour (km/h) when walking uphill, 6 km/h when walking downhill, and 4 km/h when walking on level ground. Suppose the path from Elizabeth's home to Andrew's home consists of 'x' meter in the level ground, 'y' meter in the uphill, 'z' meter in the downhill and Elizabeth starts from home by 6 a.m.Write an algorithm and the subsequent Python code to determine when Elizabeth will reach Andrew's home and when she will reach her home back if she spends 'm1' minutes in Andrew's home. For example, if x is 1000, 'y' is 500, 'z' is 300 and m1 is '30' minutes, then Elizabeth takes 30 min to reach Andrew's home so she will reach Andrew's home by 6 hour 30 min. Elizabeth will take 26 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 26 min.
The hour can be expressed in 12-hour format (not 24-hour format). The minutes elapsed should be rounded down to the nearest integer.
CODE:
x=float(input()) y=float(input()) z=float(input()) ml=float(input()) hr=6 def round2(n): if(n-round(n)>=0.5): return(round(n)+1) else: return(round(n)) tmin=round2(x/4*(18/(5*60)))+round2(y/2*(18/(5*60)))+round2(z/6*(18/(5*60))) if(tmin<60): print(hr,' ',tmin) else: hr=hr+tmin//60 tmin=tmin%60 print(hr,' ',tmin) tmin2=tmin+ml+round2(x/4*(18/(5*60)))+round2(y/6*(18/(5*60)))+round2(z/2*(18/(5*60))) if(tmin2<60): print(hr,' ',tmin2) else: hr=int(hr+tmin2//60) tmin2=int(tmin2%60) print(hr,' ',tmin2)
___________________________________________________________
-----------------------------------------------------------------------------------------
Pengrams are words or sentences containing every letter of the English alphabet at the most once. Write an algorithm and a subsequent Python code to check whether a string is a pengram or not. Write a function to check if a given string is a pengram. For example, "He is at work" is a pengram. Since every letter of the english alphabet occurs at the most once.
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
3) CSE1701 Oddophic Numbers (Id-3086)def pengram(word): p=list(word) p=list(filter(lambda a: a != ' ', p)) flag=0 for i in p: if(p.count(i)>1): flag=1 break if(flag==0): print('Pengram') else: print('Not pengram') w=input().lower() pengram(w)
________________________________________________
------------------------------------------------
Given ‘n’ integers, write an algorithm and the subsequent Python code to print all numbers that are oddophic to the first number. Two numbers with non-distinct (numbers in which digits get repeated) digits are said to be oddophic if they have the same number of digits in it and the sets of positions having the same digits contains only odd positions. Positions of digits are numbered from left to right starting from 1.
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
4) CSE1701 Non-Isomorphic Numbers (Id-3084)def same_pos(p): p=str(p) pos=[] for i in range(len(p)-1): for j in range(i+1,len(p)): if(p[i]==p[j]): pos.append(int(i)+1) pos.append(int(j)+1) return pos def odd_list(p1): flag=1 for i in p1: if(int(i)%2==0): flag=0 return flag def oddo(num1,num2): f=0 if(len(num1)==len(num2)): if(same_pos(num1)!=[] and same_pos(num2)!=[]): if(odd_list(same_pos(num1))==1 and odd_list(same_pos(num2))==1): f=1 return(f) n=int(input()) list_of_n=[] print_list=[] for i in range(n): list_of_n.append(int(input())) flag=0 for i in range(len(list_of_n)): if(oddo(str(list_of_n[0]),str(list_of_n[i]))==1): flag=1 print_list.append(list_of_n[i]) if(flag==0): print('No oddophic') else: for i in print_list: print(i)
______________________________________________________
------------------------------------------------------
Given ‘n’ integers, write an algorithm and the subsequent Python code to print all numbers that are Non-isomorphic to the first number. Two numbers with non-distinct digits ( numbers in which digits are repeated) are said to be non-isomorphic if they have the same number of digits in it and the sets of positions having the same digits are different.
CODE:(Verified👍)
def same_pos(p): pos=[] for i in range(len(p)-1): for j in range(i+1,len(p)): if(p[i]==p[j]): pos.append((i,j)) return pos def same_list(p1,p2): flag=0 if(p1!=p2): flag=1 return flag def non_iso(num1,num2): f=0 if(len(num1)==len(num2)): if(same_pos(num1)!=[] and same_pos(num2)!=[]): if(same_list(same_pos(str(num1)),same_pos(str(num2)))==1): f=1 return(f) n=int(input()) list_of_n=[] print_list=[] for i in range(n): list_of_n.append(int(input())) flag=0 for i in range(len(list_of_n)): if(non_iso(str(list_of_n[0]),str(list_of_n[i]))==1): flag=1 print_list.append(list_of_n[i]) if(flag==0): print('No non-isomorphic') else: print(list_of_n[0]) for i in print_list: print(i)
**************************************
Algorithm and Functions Used:
- same_pos(p) : This function is defined to find the set of positions having same characters in a string 'p'. It returns a list.
- same_list(p1,p2) : This function checks whether the set of positions in the two lists 'p1' and 'p2' are same or not.
______________________________________________________________-----------------------------------------------------------------------------------------
5) CSE1701 Eve number (Id-3094)
A number ‘n’ is said to be an Eve number if the reverse of the square of the number ‘n’ is not the square of the reverse of ‘n’. For example, 15 is an Eve number.
Square of 15 = 225
Reverse of 15 = 51
Square of 51= 2601 which is not the reverse of square of 15
Write an Algorithm and the subsequent Python code to check whether the given number is an Eve number or not.
Write a function to reverse a number
Input Format:
The first line will contain the number.
Output Format:
Print Eve number or Not an Eve number
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
#Function to find the reverse of a number
def rev(n):
return(int(str(n)[::-1]))
n=int(input())
if(n<0):
print('Not an Eve number')
exit()
if(rev((n)**2)==(rev(n))**2):
print('Not an Eve number')
else:
print('Eve number')
Pseudo-Code:
def rev(n):
i=len(str(n))-1
s=0
while(n):
s+=(n%10)*(10)**i
n//=10
i-=1
return(s)
Processing:
1) Define the function to find the reverse of a number
2) Read the number 'n' as input
3) Find the square of the number and the square of the reverse of number
4) If square = square of reverse : print('Not an Eve number')
else:
print('Eve number')
___________________________________________________________
-----------------------------------------------------------------------------------------
(If you have problem understanding the indentation, click to download the code as text file.)
7) CSE1701 Automorphic Numbers (Id-3088)
(If you have problem understanding the indentation, click to download the code as text file.)
-----------------------------------------------------------------------------------------
6) CSE1701 Vowgram (Id-3080)
Vowgrams are words or sentences that has every vowel of the English alphabet occurring at least once. Write an algorithm and a subsequent Python code to check whether a string is a vowgram or not. Write a function to check if a given string is a vowgram. For example, "The quick brown fox jumps over the lazy dog" is a vowgram.
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
def is_vogram(p): temp=0 if(p.count('a')>=1 and p.count('e')>=1 and p.count('i')>=1 and p.count('o')>=1 and p.count('u')>=1): temp=1 return temp s=input().lower() if(is_vogram(s)==1): print('Vowgram') else: print('Not vowgram')
___________________________________________________________
-----------------------------------------------------------------------------------------
Automorphic numbers are numbers having "n" digits such that the last n digits of the square of the number will be the number itself. Write an algorithm and the subsequent Python code to check if the given number is automorphic. Write a function to find the square of a given number.. For example, 25 is a 2 digit automorphic number with a square of 625 and 376 with its square 141376, is a 3 digit automorphic number.
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
def sqr(n): return(n*n) n=int(input()) c=sqr(n) s=0 m=len(str(n)) L=len(str(n)) for i in range(L): s+=(c%10)*(10)**i m-=1 c//=10 if(s==n): print('Automorphic') else: print('Not automorphic')
___________________________________________________________
-------------------------------------------------------------------------------------
8) CSE1701 Heterosquare Numbers (Id-3089)
(If you have problem understanding the indentation, click to download the code as text file.)
8) CSE1701 Heterosquare Numbers (Id-3089)
Heterosquare numbers are the numbers having "n" digits such that the last n digits of the square of the number will not be the number itself. .Write an algorithm and the subsequent Python code to check if the given number is a Heterosquare number. Write a function to find the square of a given number. For example, 22 is a 2 digit heterosquare number with a square of 484 and 111 with its square 12321, is a 3 digit heterosquare number.
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
def sqr(n): return(n*n) n=int(input()) c=sqr(n) s=0 m=len(str(n)) L=len(str(n)) for i in range(L): s+=(c%10)*(10)**i m-=1 c//=10 if(s==n): print('Not Heterosquare') else: print('Heterosquare')
___________________________________________________________
-----------------------------------------------------------------------------------------
9) CSE1701 Vowelgram (Id-3081)
Vowelgrams are words or sentences that has every vowel (a,e,i,o,u) of the English alphabet occurring at the most once. Write an algorithm and a subsequent Python code to check whether a string is a vowelgram or not. Write a function to check if a given string is a vowelgram. For example,”You black tiger" is a vowelgram.
Input format
First line contains the string to be checked
Output Format
Print Vowelgram or Not vowelgram
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
def is_vowelgram(p):
temp=0
if(p.count('a')<=1 and p.count('e')<=1 and p.count('i')<=1 and p.count('o')<=1 and p.count('u')<=1):
temp=1
return temp
s=input().lower()
if(is_vowelgram(s)==1):
print('Vowelgram')
else:
print('Not vowelgram')
Pseudo-Code:
def is_vowelgram(p):
temp=0
if(p.count('a')<=1 and p.count('e')<=1 and p.count('i')<=1 and p.count('o')<=1 and p.count('u')<=1):
temp=1
return temp
Processing:
1) Define the function for a string to check whether it is vowelgram or not
2) Read the string
3) if(is_vowelgram(string)==1):
print('Vowelgram')
else:
print('Not vowelgram')
___________________________________________________________
-----------------------------------------------------------------------------------------
10) CSE1701 Autocube Numbers (Id-3090)
Autocube numbers are numbers having "n" digits such that the last n digits of the cube of the number will be the number itself. Write an algorithm and the subsequent Python code to check if the given number is autocube. Write a function to find the cube of a given number.. For example, 25 is a 2 digit autocube number with a cube of 15625 and 376 with its cube 53157376, is a 3 digit autocube number.
Input Format
First line contains the number to be checked
Output Format
Print Autocube or Not autocube
*********************************************
CODE:(Verified👍)(If you have problem understanding the indentation, click to download the code as text file.)
def cube(n):
return(n*n*n)
n=int(input())
c=cube(n)
s=0
m=len(str(n))
L=len(str(n))
for i in range(L):
s+=(c%10)*(10)**i
m-=1
c//=10
if(s==n):
print('Autocube')
else:
print('Not autocube')
___________________________________________________________
-----------------------------------------------------------------------------------------
11) CSE1701 Reverseadam number (Id-3097)
A number 'n' is said to be a Reversedam number if the number is divisible by its reverse.
CODE:(Verified👍)
#Function to find the reverse of a number
def rev(num):
new=0
while(num):
f=len(str(num))
new=new+(num%10)*10**(f-1)
f-=1
num=num//10
return new
n=int(input())
r=rev(n)
if(n%r==0):
print('Reverseadam number')
else:
print('Not a reverseadam number')
___________________________________________________________
---------------------------------------------------------------------------------------
12) CSE1701 Consogram (Id-3082)
12) CSE1701 Consogram (Id-3082)
Consograms are words or sentences that has every consonant( letters other than a,e,i,o,u) of the English alphabet occurring at least once. Write an algorithm and a subsequent Python code to check whether a string is a consogram or not. Write a function to check if a given string is a consogram. For example,”"The quick brown fox jumps over the lazy dog"" is a consogram.
can u plz upload these codes
ReplyDelete1)Heterophic numbers
2)Elizabeth's morning walk
This comment has been removed by the author.
Deleteplzz upload the codes for
ReplyDelete1> diffeve number
2> elizabeth's exercise
upload the codes for CSE1701 Pangram1 (Id-3078) please
ReplyDeletefrom string import ascii_lowercase as asc_lower
ReplyDeletedef check(s):
return set(asc_lower) - set(s.lower()) == set([])
strng=input()
if(check(strng)==True):
print("Pangram")
else:
print("Not pangram")
can u please the upload the code of elizabeth's trip.please
ReplyDeletecan u upload heterocubic numbers code...??
ReplyDeleteElizabeth visits her friend Andrew and then returns home by the same route. She always walks 2 kilometers per hour (km/h) when walking uphill, 4 km/h when walking downhill, and 3 km/h when walking on level ground. Suppose the path from Elizabeth's home to Andrew's home consists of 'y' meter in the level ground, 'x' meter in the uphill, 'z' meter in the downhill and Elizabeth starts from home by 6 a.m. Write an algorithm and the subsequent Python code to determine when Elizabeth will reach Andrew's home and when she will reach her home back if she spends 'm1' minutes in Andrew's home. For example, if y is 1000, 'x’ is 500, 'z' is 300 and m1 is '30' minutes, then Elizabeth takes 40 min to reach Andrew's home so she will reach Andrew's home by 6 hour 40 min. Elizabeth will take 37 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 47 min.
ReplyDeleteThe hour can be expressed in 12-hour format (not 24-hour format). The minutes elapsed should be rounded down to the nearest integer.( is not there )
Heterocube numbers are numbers having "n" digits such that the last n digits of the cube of the number will not be the number itself. Write an algorithm and the subsequent Python code to check if the given number is heterocube. Write a function to find the cube of a given number. For example, 22 is a 2 digit heterocube number with a cube of 10648 and 111 with its cube 1367631, is a 3 digit heterocube number.( is not there)
ReplyDeleteGive the solution for ISOPHIC NUMBERS question
ReplyDeletePlease change the code of vowelgram
ReplyDeleteChange all the >= signs to <= sign
elizabeth's trip solution please..
ReplyDeleteIsomorphic Numbers give the code for this
ReplyDelete25th is last date
ReplyDeleteelizabeth's walk question code plzzz..
ReplyDeleteGive the code for Elizabeth's morning walk pls...
DeletePlease provide the code for Isophic numbers as well.
ReplyDeletePlease upload heterophic numbers
ReplyDeleteisophic numbers and elizabeth's visit pls. last day!!!!
ReplyDeleteBroh when the PPS7 answers gonna come. Reply fast please......
ReplyDelete