Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Spyder Editor
- This is a temporary script file.
- """
- #Question number 1a
- list2 =['TDB', 3063, 'Distributed Computing', 'DC']
- list2[3] = 'Software Requirement Engineering';
- print(list2)
- #Question number 2a
- str = 'SQUIRRELLED'
- newstr = str[-1:]
- print(newstr)
- #Question number 2b
- for i in range(1, 30, 5):
- print(i)
- #Question number 3
- def determineGrade(cgpa):
- if(cgpa > 3.50 and cgpa < 4.00):
- return "First Class"
- elif(cgpa >= 2.50 and cgpa <= 3.49):
- return "Second Class"
- elif(cgpa >= 1.50 and cgpa <= 2.49):
- return "Third upper Class"
- elif(cgpa >= 1.00 and cgpa <= 1.49):
- return "Fail"
- else:
- return "Error"
- userCgpa = float(input("Enter your CGPA: "))
- print(determineGrade(userCgpa))
- #Question number 5
- import calendar
- y = int(input("Input the year : "))
- m = int(input("Input the month : "))
- print(calendar.month(y, m))
- #Question number 6
- num = int(input("Input the number that need to be check: "))
- # take input from the user
- # num = int(input("Enter a number: "))
- # prime numbers are greater than 1
- if num > 1:
- # check for factors
- for i in range(2,num):
- if (num % i) == 0:
- print(num,"is not a prime number")
- print(i,"times",num//i,"is",num)
- break
- else:
- print(num,"is a prime number")
- # if input number is less than
- # or equal to 1, it is not prime
- else:
- print(num,"is not a prime number")
- #Question number 7
- import time;
- localtime = time.asctime( time.localtime(time.time()) )
- print ("Local current time :", localtime)
- #Question number 8
- list1 = [1, 2, 3, 4, 5, 6, 7 , 8 ,9]
- def find_odds(list1, odds):
- if len(list1) == 0:
- return
- v = list1.pop()
- if v % 2 == 1:
- odds.append(v)
- find_odds(list1, odds)
- odds = []
- find_odds(list1,odds)
- # Now odds has the odd numbers
- print (odds)
- #Question number 9a
- # Open a file
- fo = open("Test1.txt", "w+")
- fo.write( "Two more questions left. Hurry!!!");
- # Close opend file
- fo.close()
- #Question number 9b
- #code snippet 1
- while True:
- x = int(input("Please enter a number: "))
- print("%s squared is %s" % (x, x**2))
- #code snippet 2
- while True:
- try:
- x = int(input("Please enter a number: "))
- print("%s squared is %s" % (x, x**2))
- except ValueError:
- print("Please enter a valid number!")
- #Question number 10
- import threading
- import time
- exitFlag = 0
- class myThread (threading.Thread):
- def __init__(self, threadID, name, counter):
- threading.Thread.__init__(self)
- self.threadID = threadID
- self.name = name
- self.counter = counter
- def run(self):
- print ("Starting " + self.name)
- print_time(self.name, 5, self.counter)
- print ("Exiting " + self.name)
- def print_time(threadName, counter, delay):
- while counter:
- if exitFlag:
- threadName.exit()
- time.sleep(delay)
- print ("%s: %s" % (threadName, time.ctime(time.time())))
- counter -= 1
- # Create new threads
- thread1 = myThread(1, "Thread-1", 1)
- thread2 = myThread(2, "Thread-2", 2)
- # Start new Threads
- thread1.start()
- thread2.start()
- print ("Exiting Main Thread")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement