Your given a string of numbers A, the task is to find the max value from the string A ; you can add a '+' or '*' sign between two numbers. For Ex S=452 as 4*5*2 = 40 and 4*5+2=22 So 40 is maximum.
Write a python module Maxvalue.py for solving the above task. You need to import this module in main program. In main program define a function F-M(n) which takes a string and returns maximum value or error message as shown in example by calling the appropriate function implemented in Maxvalue,py module. Also handle the exceptions and display the exception message in the form of string. F-M(n) function must be generalized one.
Num = str(input("Enter a number: "))
MaxVal=1
for r in range(0,len(Num)):
if(Num[r]!="0" and Num[r]!="1"):
MaxVal = MaxVal*int(Num[r])
for r in range(0,len(Num)):
if(Num[r]=="1"):
MaxVal = MaxVal+int(Num[r])
print("Max. Value = ",MaxVal)
Comments
Leave a comment