Advertisement
amjadArabia

Untitled

Apr 4th, 2022
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1.  
  2. def decToOctal(decimal):#פונקציה להפיכת מספר עשרוני למספר אוקטלי
  3.     octal = 0
  4.     ctr = 0
  5.     temp = decimal  # copying number
  6.     # computing octal using while loop
  7.     while (temp > 0):
  8.         octal += ((temp % 8) * (10 ** ctr))  # Stacking remainders
  9.         temp = int(temp / 8)  # updating dividend
  10.         ctr += 1
  11.     return octal
  12.  
  13. def OctalToDecimal(num):  #פונקציה להפיכת מספר אוקטלי למספר עשרוני
  14.     decimal = 0
  15.     base = 1  #Initializing base value to 1, i.e 8^0
  16.     while (num):
  17.         # Extracting last digit
  18.         last_digit = num % 10
  19.         num = int(num / 10)
  20.         decimal += last_digit * base
  21.         base = base * 8
  22.     return decimal
  23.  
  24. def numbers_methods():
  25.     DecimalList =[]
  26.     OctalList = []
  27.     sum=0
  28.     for i in range(3):
  29.         number = int(input("enter a octal number"))
  30.         DecimalList.append(OctalToDecimal(number))
  31.         OctalList.append(number)
  32.         sum += OctalToDecimal(number)
  33.     print("the octal numbers is: ", OctalList)
  34.     print("the decimal numbers is : ", DecimalList)
  35.  
  36.     print("the sum of decimal number is : ",sum," --- in Octal is: ",decToOctal(sum))
  37.  
  38. def summer(list1):
  39.     mystring=""
  40.     newList = []
  41.     for i in range(len(list1)):
  42.         if(type(list1[i]) == int or type(list1[i]) == float):#בדיקה
  43.             return sum(list1)
  44.         elif(type(list1[i]) == bool):
  45.             return (sum(list1))
  46.         elif(type(list1[i]) == str):
  47.             mystring += list1[i]
  48.         elif(type(list1) == list):
  49.             newList = list1
  50.             return newList
  51.     return mystring
  52. def main():
  53.     #numbers_methods()
  54.     print(summer([10,11,12,0.75]))
  55.     print(summer([True,False,True,True]))
  56.     print(summer(['aa','bb','cc']))
  57.     print(summer([[1,2,3,'a'],['a','b','c',4]]))
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement