Computer Science Do Now Favorite Song; Final choose 5 programs
Final Exam (Programing Practice) Part-3
Attempt any 5 programs and You can use the codeskulptor and submit programming codes.
1. Write a program that takes a grade from the user and displays if the grade is less than or equal to 60“you are fail ”.
score = raw_input ("Enter Grade:")
sco = int (float(score))
if score < 0.60
print "you are fail"
2. Write a program that takes a number from the user and displays a message if the number is not equal 500,
Message: “Your number is not equal to 500”.
x = input ("Enter a number")
y = int(x)
if y <> 500
print "Your number is not equal to 500"
3. Write a program that takes two numbers from the user and display its sum and multiplication result.
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 + num2
print(num1, '+' , num2, ":", result)
result = num1 * num2
print(num1, '*' , num2, ":", result)
4. MISSING
5.Write a program that takes two numbers from the user and performed subtract operation. If the result comes negative it should display in positive.
See https://www.w3schools.com/python/ref_list_sort.asp
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 - num2
print(abs(result))
6. Write a program that takes Five numbers from the user and displays them in order.
import numpy as np
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
print(np.sort(arr))
7.Design a program that creates multiple variables and assigns them using compound assignment.
8.Write a program that takes a number from the user and displays the character against that number.
Attempt any 5 programs and You can use the codeskulptor and submit programming codes.
1. Write a program that takes a grade from the user and displays if the grade is less than or equal to 60“you are fail ”.
score = raw_input ("Enter Grade:")
sco = int (float(score))
if score < 0.60
print "you are fail"
2. Write a program that takes a number from the user and displays a message if the number is not equal 500,
Message: “Your number is not equal to 500”.
x = input ("Enter a number")
y = int(x)
if y <> 500
print "Your number is not equal to 500"
3. Write a program that takes two numbers from the user and display its sum and multiplication result.
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 + num2
print(num1, '+' , num2, ":", result)
result = num1 * num2
print(num1, '*' , num2, ":", result)
4. MISSING
5.Write a program that takes two numbers from the user and performed subtract operation. If the result comes negative it should display in positive.
See https://www.w3schools.com/python/ref_list_sort.asp
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 - num2
print(abs(result))
6. Write a program that takes Five numbers from the user and displays them in order.
import numpy as np
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
num3 = int(input("Enter 3rd Number: "))
num4 = int(input("Enter 4th Number: "))
num4 = int(input("Enter 4th Number: "))
num5 = int(input("Enter 5th Number: "))
arr = np.array([num1, num2, num3, num4, num5])print(np.sort(arr))
7.Design a program that creates multiple variables and assigns them using compound assignment.
- There are five compound assignment operators in Python -
- NOTES:
- += ADDITION
- -= SUBTRACTION
- *= MULTPLICATION
- /= DIVISION
- //= MODULUS divide and round down to nearest integer
- print(11//1) Note: 11/1 = 11
- print(11//2) Note: 11/2 = 5.5 round down to 5
- print(11//3) Note: 11/3 = 3.67 round down to 3
- print(11//4) Note: 11/4 = 2.75 round down to 2
- print(11//5) Note: 11/5 = 2.2 round down to 2
11 5 3 2 2
- Understanding the += operator with a code -
i=2; #initializing i to 2
i+=2; #equals to, i = i+2;
- Statement i+=2 is equal to i=i+2, hence 2 will be added to the value of i, which gives us 4.
- Finally, the result of addition, 4 is assigned back to i, updating its original value from 2 to 4.
8.Write a program that takes a number from the user and displays the character against that number.
# Program to find the ASCII value of the given character
c = input("Enter Number: ")
print("The ASCII value of '" + c + "' is", ord(c))
Comments
Post a Comment