CS256 – EXAM 1

% mean mod  and ^ mean exponent

1    Your current directory is /home. Create a new directory under todays date (nov11) and copy the file /home/nov7/answers.txt into the new directory you created.

(3 points)

2a    2 + 3 * 4 % (5 + 2 )        = 7

(3 points)

2b    165 mod 13 = 9

3     Write the output of the programs.

(6 points)

3a    n  = 90

while ( n >= 10):

if ( n % 20 == 0):

print n

n = n – 10

80 60 40 20

3b    a = ‘Hi’

b = a * 3

c = b + ‘How are you?’

d = c [0:6]

print d

HiHiHI

4    Write the output of the Program

(3 points)

str1 = ‘thIs exAM is onLY for practicING’

str2 = ‘Aa’

for ch in str1:

if  not ch.islower() and ch not in str2 and not ch.isspace() :

‘IMLYING’

print ch

5     Write down the final contents of the list. (Hint : A is less than a)

(3 points)

planets = [‘earth’,’mercury’,’Venus’,’Mars’]

planets. append ( ‘Jupiter’)

planets. sort ( )

del planets[0]

planets. reverse ( )

print planets

mercury, earth, Venus, Mars

6     Write a program to read in 3 test scores. Take the highest two scores and calculate                                average score.

OR

Print all the prime numbers between 0 to 100.

(6 points)

3 input statements

a = input(“Enter score 1”);

Write if else statements to get the biggest two.

Find the average.

Or you can put them in a list , sort it and take average from last two.

7    Write a Program to generate 10 random numbers between -100 and 100

OR

Write a program to read in date of birth and make sure it is in mm/dd/yyyy format.

import random

for i in range [0,11]:

i = random.randint(-100,101)

print i

DOB program

dob = raw_input(‘’);

length is 10

dob[2] and dob[5] is ‘\’

dob[0:2] and dob [3:5] and dob[6:10] isdigit()

8     Write a Program to read in a file name. Open the file in read mode and count the number of characters, words and lines in the file.

(10 points)

9     Write a program using Visual Python module to:

> Assign a background color of your choice

> Create a ball at position (x , y , z)= ( -1, 1, 0) of radius = 0.5 and color of your choice.

> Create a Wall at position (x , y , z) = ( 3, 0, 0) of any size and color of your choice.

> Set the rate to 100 and make the ball to bounce off on the wall.

OR

Write a program to define a Point Class, which has 2 attributes x-coordinate and              y- coordinate. In the main function create 2 points(Instances of points) at (1.0, 1.0) and       (5.0,1.0) and calculate the distance between them. (dist = sqrt( (x2-x1)^2 + (y2-y1)^2)

(10 points)

10     Bonus Question    ( 5 points)

I love playing with strings and numbers. Can you understand my message?

Harry 0-2    Heaven 3-4    Gravity 2    Winnie 3-4    Advice 4-5    Doctor 0

Eat 1        Yummy 4

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂

© 2020 customphdthesis.com. All Rights Reserved. | Disclaimer: for assistance purposes only. These custom papers should be used with proper reference.