special py
#Takes input from the user and give vowels:
try:
name = input("Enter name:")
vowel='aeiouAEIOU'
if not name.isalpha():
raise ValueError('You should enter letters only')
print('vowels are:',end='')
except ValueError as e:
print(f"Error: {e}")
for a in name:
if a in vowel:
print(a,end='')
#o/p is:
Enter name:faizan
vowels are:aia
#unique code by functions:
def first():
return" faizan is great "
def second(self):
return' %s faizan codes in python '%self
def third():
ed=first()
for a in ed:
print( second(a))
third()
#o/p is:
faizan codes in python
f faizan codes in python
a faizan codes in python
i faizan codes in python
z faizan codes in python
a faizan codes in python
n faizan codes in python
faizan codes in python
i faizan codes in python
s faizan codes in python
faizan codes in python
g faizan codes in python
r faizan codes in python
e faizan codes in python
a faizan codes in python
t faizan codes in python
faizan codes in python
#veg is 120 and non veg is 150 if distance<3 is free and upto 6 is 3 and remaining is 6 print the cost
combo=input('Enter combo (V for vegeterian or N for vegeterian ) :')
dis=int(input('Enter distance from our hotel:'))
quantity=int(input('Enter no of quantity:'))
veg_price=120
nonveg_price=150
if combo == 'V':
print(' you selected vegeterian combo ')
if dis ==3:
print(f'cost is:',veg_price*quantity)
elif dis>3 or dis<=6:
print('cost is:',veg_price*quantity+(dis-3)*3)
else:
print('cost is:',veg_price*quantity+(dis-3)*6)
elif combo=='N':
print('you selected non-vegeterian combo')
if dis ==3:
print(f'cost is:',nonveg_price*quantity)
elif dis>3 or dis<6:
print('cost is:',nonveg_price*quantity+(dis-3)*3)
else:
print('cost is:',nonveg_price*quantity+(dis-3)*6)
else:
a=-1
print(f'invalid input combo: {a}')
#o/p is:
Enter combo (V for vegeterian or N for vegeterian ) :N
Enter distance from our hotel:6
Enter no of quantity:3
you selected non-vegeterian combo
cost is: 459
#password of a user:
lass password:
def details(self,user,password,mobile_number):
self.__user=user
self.__password=int(input("Enter pass key:"))
self.mobile_number=int(input("Enter phone no:"))
def change_password(self):
if self.__password==786:
new_password = int(input("enter new password:" ))
confirm_password=int(input("enter confirm password:" ))
if new_password == confirm_password:
print("your password is updated to :",new_password)
else:
print('Both password do not mach each other')
elif self.__password != 786:
if self.mobile_number==91335964799:
print(self.__password)
else:
print("error")
p1=password()
p1.details(123456,786,91335964799)
p1.change_password()
#o/p is:
Enter pass key:786
Enter phone no:91335964799
enter new password:123
enter confirm password:123
your password is updated to : 123
#first letter is declared in some group:
stri=input("Enter name:")
if 'a'<=stri[0]<='h' or 'A'<=stri[0]<='H':
print('group1')
elif 'i'<=stri[0]<='p' or 'I'<=stri[0]<='P':
print('group2')
elif 'q'<=stri[0]<='x' or 'Q'<=stri[0] <='X':
print('group3')
elif 'y'<=stri[0]<='z' or 'Y'<=stri[0]<='Z':
print('special group')
else:
print('invalid input')
#o/p is:
Enter name:faizan
group1
PS C:\third.py> python -u "c:\third.py\lis.py"
Enter name:pop
group2
PS C:\third.py> python -u "c:\third.py\lis.py"
Enter name:quality
group3
PS C:\third.py> python -u "c:\third.py\lis.py"
Enter name:xmmas
group3
PS C:\third.py> python -u "c:\third.py\lis.py"
Enter name:yaar
special group
PS C:\third.py> python -u "c:\third.py\lis.py"
Enter name:123
invalid input
#max and min of a digit:
def fa(num):
st=str(num)
max_a=max(st)
min_a=min(st)
return int(max_a),int(min_a)
num=int(input("Enter number:"))
max_b,min_b=fa(num)
print(f'maximum digit is:{max_b}')
print(f'minimim of adigit is:{min_b}')
#o/p is:
Enter number:975
maximum digit is:9
minimim of adigit is:5
#By using oops incre and dcre:
class counting:
count=0
def increment(self):
self.count+=1
def decrement(self):
self.count-=1
def result(self):
return f'Final result is : {self.count}'
obj=counting()
a=int(input("Enter number of increment:"))
for i in range(a):
obj.increment()
b=int(input("Enter number of decrement:"))
for j in range(b):
obj.decrement()
print(obj.result())
#o/p is:
Enter number of increment:3
Enter number of decrement:2
Final result is : 1
Comments
Post a Comment