Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.32 KB | None | 0 0
  1. #Exercise -1
  2. #Дан номер некоторого года (Целое положительное число). Определить цоответствуюший ему номер столетия , учитывая #, что к примеру , #началом 20 столетия был 1901 год
  3. year = input ("provide year to detect century: ")
  4. lng = len(year)
  5. #year = int (year)
  6. ChkDig = year.isdigit()
  7. #print (ChkDig)
  8.  
  9.  
  10.  
  11. if (ChkDig) and (int(year) >= 0 or int(year) < 0):
  12.       year = int(year)
  13.       if (lng>=1 and lng<=5):
  14.             if lng==2 or lng==1:
  15.                   if year >=1:
  16.                         print("century of your provided year : 1 A.C.")
  17.                   elif year==0:
  18.                         print("century of your provided year : 1 B.C.")
  19.  
  20.             if lng==3:
  21.                   cntr= int (year//100 )
  22.                   carry = int (year - (cntr * 100))
  23.                   if carry >= 1:
  24.                         print ("century of your provided year : " , cntr+1,"A.C.")
  25.                   else:
  26.                         print ("century of your provided year : " , cntr,"A.C.")
  27.             elif lng==4:
  28.                   cntr= int(year//100 )
  29.                   carry = int(year - (cntr * 100))
  30.                   if carry >= 1:
  31.                         print("century of your provided year : ", cntr + 1,"A.C.")
  32.                   else:
  33.                         print("century of your provided year : ", cntr ,"A.C.")
  34.  
  35. elif (int(year) < 0) or (lng>=2 and lng<=5):
  36.       year = int(year)
  37.       if lng == 4:
  38.             cntr = (-year // 100 )
  39.             carry = int(year - (cntr * 100))
  40.             if carry == 99:
  41.                   print("century of your required year : ", cntr + 1, "B.C.")
  42.             else:
  43.                   print("century of your required year : ", cntr, "B.C.")
  44.       elif lng == 5:
  45.             cntr = (-year // 100 )
  46.             carry = int(year - (cntr * 100))
  47.             if carry == 99:
  48.                   print("century of your required year : ", cntr + 1, "B.C.")
  49.             else:
  50.                   print("century of your required year : ", cntr, "B.C.")
  51.       elif lng == 3 or lng ==2:
  52.             if year > -99:
  53.                   print ("century of your required year : 1 B.C.")
  54.             elif year == -99:
  55.                   print ("century of your required year : 1 A.C.")
  56. else:
  57.       print ("not an year at all !!!")
  58.  
  59.  
  60.      
  61.  
  62. #-------------------------------------------------------------------------------------
  63. #Exercise -2
  64. #Проверить истиность вусказывания : <<Среди тре данных целых чисел хотя бы одна пара взаимно противоположных>>.
  65. num1 = int (input ("provide num1 "))
  66. num2 = int (input ("provide num2 "))
  67. num3 = int (input ("provide num3 "))
  68.  
  69.  
  70. if (num1==-num2) or (num1==-num3) or (num2==-num3):
  71.       print("your statement is true ")
  72. else:
  73.       print ("your statement is not occur ")
  74.  
  75. #-------------------------------------------------------------------------------------
  76. #Exercise -3
  77. #Дано трехзначное число . Проверить истиность высказывания : <<Все цифры данного числа различны>>
  78.  
  79.  
  80. num = input ("provide number 3 digit length ")
  81.  
  82. if (num.isdigit()):
  83.       len = len(num)
  84.       num = int(num)
  85.       if (len==3) :
  86.             a = int(num//100 % 10)
  87.             b = int(num//10 % 10)
  88.             c = int(num % 10)
  89.             if (a!=b and b!=c and a!=c):
  90.                   print ("you right all 3 digits are different")
  91.             else:
  92.                   print("some of your digits are equal")
  93.       else:
  94.             print ("you provided number with wrong length")
  95. else:
  96.       print ("you didnt provided a number at all")
  97.  
  98.  
  99. #-------------------------------------------------------------------------------------
  100.  
  101. #Exercise -4
  102. #Дано четерехзначное число . Проверить истиность высказывания :<<Данное число читается одинаково слева направо и #справа налево>>
  103.  
  104. num = input ("provide number 4 digit length ")
  105. lng = len(num)
  106. Chk = num.isdigit()
  107.  
  108. if (Chk) and lng==4:
  109.       num= int(num)
  110.       a = (num //1000 %10)
  111.       b = (num // 100 % 10)
  112.       c = (num // 10 % 10)
  113.       d = (num % 10)
  114.       if a==d and b==c :
  115.             print ("your number is POLYNDROM")
  116.       else:
  117.             print("your number is not POLYNDROM")
  118. elif (not Chk) :
  119.       print ("It is string and not a number")
  120. elif lng!=4 and (Chk):
  121.       print("you number difirent then 4 digits")
  122.  
  123. #-------------------------------------------------------------------------------------
  124. #exersise 5
  125.  
  126. #Еще такая задача:
  127. #The program will first compute the tax you owe based on your income.
  128. #User is prompted to enter income.
  129. #Program will compute the total amount of tax owed based on the following:
  130.  
  131. #Income Tax
  132. #0 - $45,000 = 0.15 x income
  133. #$45,001 - $90,000 = 6750 + 0.20 x (income – 45000)
  134. #$90,001 - $140,000 = 15750 + 0.26 x (income – 90000)
  135. #$140,001 - $200,000 = 28750 + 0.29 x (income – 140000)
  136. #Greater than $200,000 = 46150 + 0.33 x (income – 200000)
  137.  
  138. #Dollar amounts should be in dollars and cents (float point numbers with two decimals shown).
  139.  
  140.  
  141.  
  142. salary = input("what is your salary: ")
  143. Chk = salary.isdigit()
  144. if Chk :
  145.       salary = int(salary)
  146.       if salary>0 and salary<=45000 :
  147.             tax = float (0.15 * salary)
  148.             print ("%-10s %.2f$"%("your taxes , are  : " ,tax ))
  149.       elif salary>=45001 and salary<=90000:
  150.             tax = 6750 + float(0.2*(salary-45000))
  151.             print("%-10s %.2f$" % ("your taxes , are  : ", tax))
  152.       elif salary>=90001 and salary<=140000:
  153.             tax = 15750 + float(0.26*(salary-90000))
  154.             print("%-10s %.2f$" % ("your taxes , are  : ", tax))
  155.       elif salary>=140001 and salary<=200000:
  156.             tax = 28750 + float(0.29*(salary-140000))
  157.             print("%-10s %.2f$" % ("your taxes , are  : ", tax))
  158.       elif salary>200000 :
  159.             tax = 46150 + float(0.33*(salary-200000))
  160.             print("%-10s %.2f$" % ("your taxes , are  : ", tax))
  161.       elif salary==0:
  162.             print ("you got taxes exemption ")
  163.  
  164. else:
  165.       print ("not a salary at all- seems as rubbish")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement