Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

COSC 1436 Lab 4 Assignment

COSC 1436 Lab 4 Assignment

COSC 1436 Lab 4 Assignment

Name (First Last):

Data Representation II

1. (3 points, each for 0.5 point) Convert the following positive binary numbers to their decimal number equivalents, showing all steps.

a) 111111

b) 1110.11

c) 101111.101

d) 10111110.00001

e) 110011.011

2. (4 points, each for 0.5 point) Convert the following positive decimal numbers to their binary equivalents showing all steps. If needed, you can attach more papers.

a) 4.25

b) 0.9375

c) 254.75

d) 0.5625

e) 127.875

f) 104

g) 0.7578125

h) 3.125

3. (2 points) How many things can be represented with:

a. four bits

b. five bits

c. six bits

d. seven bits

4. (2 points) Using the following number line representation, evaluate the expressions by showing all steps:

999

500 501 502 … 997 998 0 1 2 3 … 497 498 499

-500 -499 -498 … -3 -2 -1 0 1 2 3 … 497 498 499

a. 498 + (-7)

b. -5 + (-2)

c. 5 – 8

d. -500+6

5. (3 points) Given a fixed-sized number scheme where k in the formula for the ten’s complement is 6 , answer the following questions.

a. How many positive integers can be represented?

b. How many negative integers can be represented?

c. Draw the number line showing the three smallest and largest positive numbers, the three smallest and largest negative numbers, and zero.

6. (3 points) Using the number line in Qn5, find out the ten’s complement representation of the following numbers. Show all steps.

a. 35768

b. –35768

c. –444455

d. –123456

e. -23456

7. (5 points) Roulette Wheel Colors: On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows:

· Pocket 0 is green.

· For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black.

· For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red.

· For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black.

· For pockets 29 through 36, the odd-numbered pockets are black and the even-numbered pockets are red.

By referring to Figure 1, write a program that asks the user to enter a pocket number and displays whether the pocket is green, red, or black. The program should display an error message if the user enters a number that is outside the range of 0 through 36. (Hint: use if-elif-else and nested if-else statements)

Before programming, we can have some fun first. An online game is available at https://www.vegasslotsonline.com/table-games/american-roulette/

Image result for Roulette Wheel Colors

Figure 1: Roulette Wheel Colors

· Source code of the project

#python program

· Screenshot of the output

· Save the program as “Roulette.py”

8. (1 point) What does the following loop print?

n = 1

while n < 100 : n = 2 * n print(n) 9. (1 point) Hand-trace the following code, showing the value of n and the output. n = 5 while n >= 0 :

n = n – 1

print(n)

10. (1 point) Hand-trace the following code, showing the value of n and the output.

n = 1

while n <= 3 : print(n) n = n + 1 11. (1 point) Hand-trace the following code, assuming that a is 2 and n is 4. Then explain what the code does for arbitrary values of a and n. r = 1 i = 1 while i <= n : r = r * a i = i + 1 12. (1 point) Hand-trace the following code. What error do you observe? n = 1 while n != 50 : print(n) n = n + 10 13. (2 point) What is wrong with the following loop for finding the smallest input value? smallest = 0 inputStr = input("Enter a value: ") while inputStr != "" : value = int(inputStr) if value < smallest : smallest = value inputStr = input("Enter a value: ") 14. (1 point) How many numbers does this loop print? for n in range(10, -1, -1) : print(n) 15. (2 points) Write a for loop that prints all even numbers between 10 and 20 (inclusive). 16. (5 points) Write while loops that prints a) All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b) All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c) All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64. · Source code of the project #python program · Screenshot of the output · Save the program as “Qn16.py” 17. (3 points) Number guessing game – First, we use randint to generate a random number N between 1 and 100: from random import randint N = randint(1, 100) Complete the program. The program shall ask the user to guess what N is. Every time the user makes a guess, the program shall tell the user whether the guessed number is greater than, equal to, or less than N. If the guessed number equals to N, the program should terminate. You may assume that the user only types integers. · Source code of the project #python program · Screenshot of the output · Save the program as “Qn17.py” 18. (5 points) Write loops that computes a) The sum of all even numbers between 2 and 100 (inclusive). b) The sum of all squares between 1 and 100 (inclusive). c) The sum of all odd numbers between a and b (inclusive). d) The sum of all odd digits of n. (For example, if n is 32677, the sum would be 3 + 7 + 7 = 17.) · Source code of the project #python program · Screenshot of the output · Save the program as “Qn18.py” Applied Sciences Architecture and Design Biology Business & Finance Chemistry Computer Science Geography Geology Education Engineering English Environmental science Spanish Government History Human Resource Management Information Systems Law Literature Mathematics Nursing Physics Political Science Psychology Reading Science Social Science Home Blog Archive Essay Reviews Contact Copyright © 2019 HomeworkMarket.comHOMEWORKMARKET.COM – YOUR HOMEWORK ANSWERSHomeworkMarket chat0 Home.Homework Answers. Help. Log in / Sign up python assignment profile prity29137 cosc14363.docx Home>Computer Science homework help>python assignment
Total Grade (45 pts)

COSC 1436 Lab 4 Assignment

Name (First Last):

Data Representation II

1. (3 points, each for 0.5 point) Convert the following positive binary numbers to their decimal number equivalents, showing all steps.

a) 111111

b) 1110.11

c) 101111.101

d) 10111110.00001

e) 110011.011

2. (4 points, each for 0.5 point) Convert the following positive decimal numbers to their binary equivalents showing all steps. If needed, you can attach more papers.

a) 4.25

b) 0.9375

c) 254.75

d) 0.5625

e) 127.875

f) 104

g) 0.7578125

h) 3.125

3. (2 points) How many things can be represented with:

a. four bits

b. five bits

c. six bits

d. seven bits

4. (2 points) Using the following number line representation, evaluate the expressions by showing all steps:

999

500 501 502 … 997 998 0 1 2 3 … 497 498 499

-500 -499 -498 … -3 -2 -1 0 1 2 3 … 497 498 499

a. 498 + (-7)

b. -5 + (-2)

c. 5 – 8

d. -500+6

5. (3 points) Given a fixed-sized number scheme where k in the formula for the ten’s complement is 6 , answer the following questions.

a. How many positive integers can be represented?

b. How many negative integers can be represented?

c. Draw the number line showing the three smallest and largest positive numbers, the three smallest and largest negative numbers, and zero.

6. (3 points) Using the number line in Qn5, find out the ten’s complement representation of the following numbers. Show all steps.

a. 35768

b. –35768

c. –444455

d. –123456

e. -23456

7. (5 points) Roulette Wheel Colors: On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows:

· Pocket 0 is green.

· For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black.

· For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red.

· For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black.

· For pockets 29 through 36, the odd-numbered pockets are black and the even-numbered pockets are red.

By referring to Figure 1, write a program that asks the user to enter a pocket number and displays whether the pocket is green, red, or black. The program should display an error message if the user enters a number that is outside the range of 0 through 36. (Hint: use if-elif-else and nested if-else statements)

Before programming, we can have some fun first. An online game is available at https://www.vegasslotsonline.com/table-games/american-roulette/

Image result for Roulette Wheel Colors

Figure 1: Roulette Wheel Colors

· Source code of the project

#python program

· Screenshot of the output

· Save the program as “Roulette.py”

8. (1 point) What does the following loop print?

n = 1

while n < 100 : n = 2 * n print(n) 9. (1 point) Hand-trace the following code, showing the value of n and the output. n = 5 while n >= 0 :

n = n – 1

print(n)

10. (1 point) Hand-trace the following code, showing the value of n and the output.

n = 1

while n <= 3 : print(n) n = n + 1 11. (1 point) Hand-trace the following code, assuming that a is 2 and n is 4. Then explain what the code does for arbitrary values of a and n. r = 1 i = 1 while i <= n : r = r * a i = i + 1 12. (1 point) Hand-trace the following code. What error do you observe? n = 1 while n != 50 : print(n) n = n + 10 13. (2 point) What is wrong with the following loop for finding the smallest input value? smallest = 0 inputStr = input("Enter a value: ") while inputStr != "" : value = int(inputStr) if value < smallest : smallest = value inputStr = input("Enter a value: ") 14. (1 point) How many numbers does this loop print? for n in range(10, -1, -1) : print(n) 15. (2 points) Write a for loop that prints all even numbers between 10 and 20 (inclusive). 16. (5 points) Write while loops that prints a) All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b) All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c) All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64. · Source code of the project #python program · Screenshot of the output · Save the program as “Qn16.py” 17. (3 points) Number guessing game – First, we use randint to generate a random number N between 1 and 100: from random import randint N = randint(1, 100) Complete the program. The program shall ask the user to guess what N is. Every time the user makes a guess, the program shall tell the user whether the guessed number is greater than, equal to, or less than N. If the guessed number equals to N, the program should terminate. You may assume that the user only types integers. · Source code of the project #python program · Screenshot of the output · Save the program as “Qn17.py” 18. (5 points) Write loops that computes a) The sum of all even numbers between 2 and 100 (inclusive). b) The sum of all squares between 1 and 100 (inclusive). c) The sum of all odd numbers between a and b (inclusive). d) The sum of all odd digits of n. (For example, if n is 32677, the sum would be 3 + 7 + 7 = 17.) · Source code of the project #python program · Screenshot of the output · Save the program as “Qn18.py” Applied Sciences Architecture and Design Biology Business & Finance Chemistry Computer Science Geography Geology Education Engineering English Environmental science Spanish Government History Human Resource Management Information Systems Law Literature Mathematics Nursing Physics Political Science Psychology Reading Science Social Science Home Blog Archive Essay Reviews Contact Copyright © 2019 HomeworkMarket.com

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Blackboard Experts only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Blackboard Experts are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Blackboard Experts is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Blackboard Experts, we have put in place a team of experts who answer to all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.