Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor
  4.  
  5. This is a temporary script file.
  6. """
  7. #Question number 1a
  8. list2 =['TDB', 3063, 'Distributed Computing', 'DC']
  9. list2[3] = 'Software Requirement Engineering';
  10.  
  11. print(list2)
  12.  
  13.  
  14. #Question number 2a
  15. str = 'SQUIRRELLED'
  16. newstr = str[-1:]
  17. print(newstr)
  18.  
  19. #Question number 2b
  20. for i in range(1, 30, 5):
  21. print(i)
  22.  
  23.  
  24.  
  25. #Question number 3
  26. def determineGrade(cgpa):
  27. if(cgpa > 3.50 and cgpa < 4.00):
  28. return "First Class"
  29. elif(cgpa >= 2.50 and cgpa <= 3.49):
  30. return "Second Class"
  31. elif(cgpa >= 1.50 and cgpa <= 2.49):
  32. return "Third upper Class"
  33. elif(cgpa >= 1.00 and cgpa <= 1.49):
  34. return "Fail"
  35. else:
  36. return "Error"
  37.  
  38. userCgpa = float(input("Enter your CGPA: "))
  39. print(determineGrade(userCgpa))
  40.  
  41.  
  42.  
  43. #Question number 5
  44. import calendar
  45. y = int(input("Input the year : "))
  46. m = int(input("Input the month : "))
  47. print(calendar.month(y, m))
  48.  
  49.  
  50. #Question number 6
  51.  
  52.  
  53. num = int(input("Input the number that need to be check: "))
  54.  
  55. # take input from the user
  56. # num = int(input("Enter a number: "))
  57.  
  58. # prime numbers are greater than 1
  59. if num > 1:
  60. # check for factors
  61. for i in range(2,num):
  62. if (num % i) == 0:
  63. print(num,"is not a prime number")
  64. print(i,"times",num//i,"is",num)
  65. break
  66. else:
  67. print(num,"is a prime number")
  68.  
  69. # if input number is less than
  70. # or equal to 1, it is not prime
  71. else:
  72. print(num,"is not a prime number")
  73.  
  74.  
  75. #Question number 7
  76. import time;
  77.  
  78. localtime = time.asctime( time.localtime(time.time()) )
  79. print ("Local current time :", localtime)
  80.  
  81. #Question number 8
  82. list1 = [1, 2, 3, 4, 5, 6, 7 , 8 ,9]
  83.  
  84. def find_odds(list1, odds):
  85. if len(list1) == 0:
  86. return
  87. v = list1.pop()
  88. if v % 2 == 1:
  89. odds.append(v)
  90. find_odds(list1, odds)
  91.  
  92. odds = []
  93. find_odds(list1,odds)
  94. # Now odds has the odd numbers
  95. print (odds)
  96.  
  97.  
  98. #Question number 9a
  99. # Open a file
  100. fo = open("Test1.txt", "w+")
  101. fo.write( "Two more questions left. Hurry!!!");
  102.  
  103. # Close opend file
  104. fo.close()
  105.  
  106. #Question number 9b
  107. #code snippet 1
  108. while True:
  109. x = int(input("Please enter a number: "))
  110. print("%s squared is %s" % (x, x**2))
  111.  
  112. #code snippet 2
  113. while True:
  114. try:
  115. x = int(input("Please enter a number: "))
  116. print("%s squared is %s" % (x, x**2))
  117. except ValueError:
  118. print("Please enter a valid number!")
  119.  
  120. #Question number 10
  121. import threading
  122. import time
  123.  
  124. exitFlag = 0
  125.  
  126. class myThread (threading.Thread):
  127. def __init__(self, threadID, name, counter):
  128. threading.Thread.__init__(self)
  129. self.threadID = threadID
  130. self.name = name
  131. self.counter = counter
  132. def run(self):
  133. print ("Starting " + self.name)
  134. print_time(self.name, 5, self.counter)
  135. print ("Exiting " + self.name)
  136.  
  137. def print_time(threadName, counter, delay):
  138. while counter:
  139. if exitFlag:
  140. threadName.exit()
  141. time.sleep(delay)
  142. print ("%s: %s" % (threadName, time.ctime(time.time())))
  143. counter -= 1
  144.  
  145. # Create new threads
  146. thread1 = myThread(1, "Thread-1", 1)
  147. thread2 = myThread(2, "Thread-2", 2)
  148.  
  149. # Start new Threads
  150. thread1.start()
  151. thread2.start()
  152.  
  153. print ("Exiting Main Thread")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement