Total Grade (30 Pts) COSC 1436 Weeks 5-6 Lab Assignment 3

Total Grade (30 pts) COSC 1436 Weeks 5-6 Lab Assignment -3 Name (First Last): Data Conversions and Control structures I

Convert each of following numbers to Octal numbers, showing all steps.

a. (A9)16

b. (5FF)

Convert each of following numbers to Binary numbers, showing all steps.

a. (572)8

b. ( )

c. ( )

d. (99)10

e. (80E)16

f. (135AB)

Convert each of following numbers to Hexadecimal numbers, showing all steps.

a. ( )

b. ( )

c. (777)8

d. (443)8

e. (998)10

f. ( )

Evaluate the following expressions. For each expression, keep the same number system as it is. Do not convert the number systems. E.g., if the expression is written in hexadecimal, answer in hexadecimal.

a. (+( )

b. ( )

c. (202)8 + (667)8

d. (+ (ABCD)16)

e. ( )

f. (–(AB)

Write a program to ask the user to type the height of a person in inches, and convert it to feet and inches. Your program should run like this:

Enter your height in inches: 71

Your height is 5' 11".

Sample Python code (“height.py”):

height_inches = int(input("Enter your height in inches: "))

feet = height_inches // 12

remaining_inches = height_inches % 12

print(f"Your height is {feet}' {remaining_inches}\"")

Write a program to ask the user to input the radius of a sphere, and then display the volume of the sphere. Use the formula: volume = (4/3) π r³, where π is approximately 3.14159.

Sample Python code (“sphere.py”):

import math

radius = float(input("Enter the radius of the sphere: "))

volume = (4/3) 3.14159 radius ** 3

print(f"The volume of the sphere is {volume:.2f}")

Complete the following logical operator truth table by circling T or F for each result:

ExpressionResult (circle T or F)
True and FalseT / F
True and TrueT / F
False and TrueT / F
False and FalseT / F
True or FalseT / F
False or TrueT / F
False or FalseT / F
not TrueT / F
not FalseT / F

Assuming variables a=2, b=4, c=6, x=0, y=2, z=4, determine whether each condition is true or false by circling T or F:

Expression (Condition)Result (circle T or F)
a == 4 or b > 2T / F
6 3T / F
1 != b and c != 3T / F
a >= -1 or a T / F
not (a > 2)T / F
x or yT / F
x and yT / F
x or zT / F
(x and y) or (y and z)T / F
not yT / F

Write logical expressions for the following conditions:

  1. x is not a negative number
  2. x is a multiple of 7
  3. x is greater than the sum of y and z
  4. x is the greatest number among x, y, and z
  5. x is less than 99 but greater than ...

What will the following code display?

a) if 'z'

b) s1 = 'New York' s2 = 'Boston' if s1 > s2: print(s2) print(s1) else: print(s1)

Flowchart and code fragment exercises: (do not include actual flowcharts here, just the task)

a) if variable x > 100, assign y=20 and z=40

b) if a

c) if a

d) if speed between 24 and 56, display 'Speed is normal'; else 'Speed is abnormal'

e) if points outside 9-51, display 'Invalid points'; else 'Valid points'

f) if amount1 > 10 and amount2

Write a program to input two integers and print:

  1. The sum
  2. The difference
  3. The product
  4. The average
  5. The distance (absolute difference)
  6. The maximum
  7. The minimum

Sample Python code (“Calculation.py”):

num1 = int(input("Enter first integer: "))

num2 = int(input("Enter second integer: "))

print(f"Sum: {num1 + num2}")

print(f"Difference: {num1 - num2}")

print(f"Product: {num1 * num2}")

print(f"Average: {(num1 + num2)/2}")

print(f"Distance: {abs(num1 - num2)}")

print(f"Max: {max(num1, num2)}")

print(f"Min: {min(num1, num2)}")

Write a program that initializes a string variable and prints the first three characters, followed by three periods, then the last three characters. For example, "Mississippi" becomes "Mis...ppi".

Sample Python code (“shorterString.py”):

s = "Mississippi"

print(s[:3] + "..." + s[-3:])