Skip to main content

Posts

Showing posts with the label solution

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 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:             ...