In: Computer Science
use *python
Though CPUs, and computer hardware in-general, are not the main focus of this course, it can be useful to know a thing or two about computer hardware. The CPU (Central Processing Unit) is generally the piece of hardware that carries out the instructions of the python programs that you run in this class.
In this short PA, you will write a program that takes a few input values related to CPU performance. The program should determine whether or not the specified CPU is within one of four categories: high-performance, medium-performance, low-performance, and in need of an upgrade. Name the file cpu.py. Shown below is an example of the program prompting the user for three inputs, and then printing out the corresponding CPU performance category:
Press ENTER or type command to continue Enter CPU gigahertz: 2.7 Enter CPU core count: 2 Enter CPU hyperthreading (True or False): False That is a low-performance CPU
The program should spit out one of 4 strings:
How you determine which to print out should be based on the below tables:
If the CPU has hyperthreading
performance level | min GHz | min cores |
high-performance | 2.7 | 6 |
medium-performance | 2.4 | 4 |
low-performance | 1.9 | 2 |
If the CPU does not have hyperthreading
performance level | min GHz | min cores |
high-performance | 3.2 | 8 |
medium-performance | 2.8 | 6 |
low-performance | 2.4 | 2 |
There’s also one “special-case” rule: If a CPU has 20 or more cores, regardless of the other stats, it should be considered high-performance.
Examples
Below are several examples of program runs. There will be more tests on Gradescope.
Enter CPU gigahertz: 2.0 Enter CPU core count: 8 Enter CPU hyperthreading (True or False): True That is a low-performance CPU.
Enter CPU gigahertz: 4.0 Enter CPU core count: 6 Enter CPU hyperthreading (True or False): False That is a medium-performance CPU.
'''
Python version : 2.7
Python program to determine the whether or not the specified CPU is within one of four categories:
high-performance, medium-performance, low-performance, and in need of an upgrade.
'''
# input of cpu gigahertz
cpu_ghz = float(raw_input('Enter CPU gigahertz:\n'))
# input of cpu cores count
cpu_cores = int(raw_input('Enter CPU core count:\n'))
# input of cpu hyperthreading
cpu_hyperthreading_input = raw_input('Enter CPU hyperthreading (True or False):\n')
# convert the string input to boolean
if cpu_hyperthreading_input == 'True':
cpu_hyperthreading = True
else:
cpu_hyperthreading = False
# check if cpu cores >= 20, then high performance cpu
if cpu_cores >=20:
print('That is high-performance CPU.')
elif cpu_hyperthreading == True: # check if hyperthreading is True
# cpu gigahertz is min 2.7 and cores are min 6, then high performance
if(cpu_ghz >= 2.7 and cpu_cores >= 6):
print('That is high-performance CPU.')
# cpu gigahertz is min 2.4 and cores are min 4, then medium performance
elif(cpu_ghz >=2.4 and cpu_cores >= 4):
print('That is medium-performance CPU.')
# cpu gigahertz is min 1.9 and cores are min 2, then low performance
elif(cpu_ghz >= 1.9 and cpu_cores >= 2):
print('That is low-performance CPU.')
else: # needs an upgrade
print('That CPU could use an upgrade.')
else: # check if hyperthreading is False
# cpu gigahertz is min 3.2 and cores are min 8, then high performance
if(cpu_ghz >= 3.2 and cpu_cores >= 8):
print('That is high-performance CPU.')
# cpu gigahertz is min 2.8 and cores are min 6, then medium performance
elif(cpu_ghz >= 2.8 and cpu_cores >= 6):
print('That is medium-performance CPU.')
# cpu gigahertz is min 2.4 and cores are min 2, then low performance
elif(cpu_ghz >= 2.4 and cpu_cores >= 2):
print('That is low-performance CPU.')
else: # needs an upgrade
print('That CPU could use an upgrade.')
#end of program
Code Screenshot:
Output: