0% found this document useful (0 votes)
55 views

Python Programming Tasks

This document outlines 4 tasks for a Python programming assignment on applied thermodynamics. The tasks include: 1) performing mathematical operations on user-input numbers, 2) converting temperatures between Celsius and Fahrenheit, 3) creating and printing a user-defined list, and 4) writing a series of numbers to a file based on user input and printing lines from the file. Hints are provided for loops and functions to use for each task.

Uploaded by

Bebe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Python Programming Tasks

This document outlines 4 tasks for a Python programming assignment on applied thermodynamics. The tasks include: 1) performing mathematical operations on user-input numbers, 2) converting temperatures between Celsius and Fahrenheit, 3) creating and printing a user-defined list, and 4) writing a series of numbers to a file based on user input and printing lines from the file. Hints are provided for loops and functions to use for each task.

Uploaded by

Bebe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Applied

thermodynamics: Thermodynamical Properties for Industrial Applications. WS 18/19


Python programming tasks


Task 1: Operations
In this task, the user will introduce a desired operation and two numbers of interest. The numbers
will be saved in the variables “a” and “b”, and the operation will be saved under “operation”.
Possible operations: addition (+), subtraction (-), division (/), power (**). The program will resolve
the corresponding operation depending on the result given by the user.

**Note: If the user does not introduce one of the specified operations, print an error
message.
**HINT: Which function do you have to use in order to save the desired operation given by
the user in the variable “operation”, input or raw_input?

Interacting with your program should look something like this:

Task 2: Conversion
In this task, the program will convert a temperature given by the user from Celsius to Fahrenheit or
vice versa. For this aim, the user will be asked for the desired option, which is going to be saved in
the variable “option” (For this, you have to use the function raw_input, not input).:

- "Option 1: Convert Fahrenheit to Celsius"


- "Option 2: Convert Celsius to Fahrenheit"
**Note: If the user does not introduce one of the specified option numbers, print an error
message.
**HINT: Which loop do you need to use in order to carry out the desired conversion?

Interacting with your program should look something like this:


Applied thermodynamics: Thermodynamical Properties for Industrial Applications. WS 18/19

Task 3: Lists
In this task, you have to create a list under the name “my_apartment” and save things you have in
your apartment, as many as you want. Print the list and say at the end how many things are in your
apartment.

**HINT: Which loop do you need to use in order to print the variables of the list? Can you
use the len function to count the variables? How?

Interacting with your program should look something like this:

Task 4: File input and output


In this task, you have to create a new file under the name “yourname_file”. To this aim, use the
function open from python.

In this file, a series of numbers in which 2*n is the step size will be saved. n is a number introduced
by the user. For instance, if n=3, the series would be: 6, 12, 18, 24,... You have also to ask the user for
the maximum amount of numbers that are going to be printed.

**HINT: In order to interact with the file, use the functions write and read from python. Use
a while loop to read the file and print the written lines in the file.

Interacting with your program should look something like this:

You might also like