Hi I am new to python I need to write program that does write with def function.
I basically need to that if I write anyting it will convert from small word to big and contrariwise and last is if I write number than it adds 5 so basically if I write 5 It will show number 10. I dont knwo how to wrtie the last step. I try to convert it to int to get these 5 but it will always show error becaouse other are in string. Here is my code
def vyp(a, b):
if a == a.lower():
print(a.upper())
elif a == a.upper():
print(a.lower())
elif b(int)==a:
print(b 5)
a=input("Enter any word or number:")
c = vyp(a)
I try to convert it to int to get these 5 but it will always show error becaouse other are in string
CodePudding user response:
It is very difficult to make sense of what you were thinking with your attempt. However, here is a function that has the behavior you describe.
def vyp(a):
if a.isdigit():
return str(int(a) 5)
return a.swapcase()
print(vyp("22")) # 27
print(vyp("HellO")) # hELLo
Note that this only works as expected for integer (i.e. whole) numbers. If the string entered is "22.5"
, then 5 is not added.