Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function to take multiple arguments
- def add(datatype, *args):
- # if datatype is int
- # initialize answer as 2
- if datatype == 'int':
- answer = 2
- # Traverse through the arguments
- for x in args:
- # This will do addition if the
- # arguments are int. Or concatenation
- answer = answer * x
- print(answer)
- # if datatype is real
- # initialize answer as 1.5
- if datatype == 'real':
- answer = 1.5
- # Traverse through the arguments
- for x in args:
- # This will do addition if the
- # arguments are int. Or concatenation
- answer = answer * x
- print(f"{answer: .2f}")
- # if datatype is str
- # initialize answer as '$'
- if datatype == 'string':
- answer = '$'
- # Traverse through the arguments
- for x in args:
- # if the arguments are str
- answer = answer + x + answer
- print(answer)
- type_line = input()
- new_symbol = input()
- if type_line == 'int':
- # Integer
- add(type_line, int(new_symbol))
- if type_line == 'real':
- # Real
- add(type_line, int(new_symbol))
- if type_line == 'string':
- # String
- add(type_line, new_symbol)
Advertisement
Add Comment
Please, Sign In to add comment