Skip to main content

Posts

Showing posts with the label calculator

Python - Basic Mathematical Calculator

🐍  In Python, write a code to let users carry out basic mathematical calculations that include addition, subtraction, multiplication, and division. Solution def basic_operation(a, b, opp):     if opp[0] == '+':         return a+b     elif opp[0] == '-':         return a-b     elif opp[0] == '*':         return a*b     elif opp[0] == '/':         return a/b if __name__ == '__main__':     a = float(input('Enter first number: '))     opp = input("+ - * / ")     b = float(input('Enter second number: '))     print(basic_operation(a, b, opp))

Python - Convert Decimal Number to Binary

🐍  Using Python, create a converter that converts decimal base number into binary base number. Solution def convertDecimalToBinary(decinum):          binum = ''     rem = decinum          while rem>0:         binum = binum + str(rem%2)         rem = rem//2          return binum[::-1] if __name__=='__main__':          decinum = int(input("Enter a decimal number: "))     print(f'The binary equivalent of {decinum} is {convertDecimalToBinary(decinum)}')

Python - Calculate Money Change and Denomination

🐍  Python program to calculate change and denominations. The user enters the price and then the amount of money given. The program will figure out the change and the number of ones, twos, fives, tens, twenties, fifties, hundreds, two hundreds, and thousands to be returned. Use dictionary data type. Solution def changecalculator(bill, received):     if received > bill:         change_dic = {'thousand' : 0, 'fivehundred' : 0, 'twohundred' : 0, 'hundred' : 0, 'fifty' : 0, 'twenty' : 0, 'ten' : 0, 'five' : 0, 'two' : 0, 'one' : 0}         changeof = received - bill         rem = changeof         print(f"Amount to be returned: {rem}")         while rem > 0:             if rem >= 1000:                 change_dic['thousand'] += rem//1000                 rem = rem...

Python - Mortgage EMI Calculator

🐍  Using Python, write a program to calculate the monthly payments of a mortgage at a given interest rate. Also figure out how long it will take the user to pay back the loan. For added complexity, add an option for users to select the compounding interval (Yearly, Bi-Yearly, Quarterly, Monthly, Weekly, Daily) Solution def emicalculator(loan, interest, interval, emi):     day_count = 0     remaining = loan     if interval[0].lower()=='d':         while remaining > 0:             day_count += 1             remaining += (interest/100)*remaining             if day_count%30==0:                 remaining -= emi                 if remaining>=loan:                     print('Either lower interest rate or increase EMI...

Python - Calculate Number of Tiles Required And Total Expenditure

🐍  In Python, calculate the total cost of tile it would take to cover a floor plan of width and height, using a cost entered by the user. Solution def tile_calculator(roomlen, roomwid, tilelen, tilewid, tileprice):          if roomlen!=0 and roomwid!=0 and tilelen!=0 and tilewid!=0:                  if roomlen%tilelen==0:             notileslen = int(roomlen//tilelen)                          if roomwid%tilewid==0:                 notileswid = int(roomwid//tilewid)                          else:                 notileswid = int((roomwid//tilewid)+1)                  elif roomlen%tilewid==0:             ...