CSE110 Lab Assignment 1 - Data Types, Variables, and I - O

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Course Title: Programming Language I

Course Code: CSE 110


Assignment no: 1
Attention
Students must ensure that they have collected the lab login credentials (it is not the G-suite
account) before attending the lab to access the lab computers. The login information was sent
to students' USIS-registered email addresses. If not found, students should request login
information by emailing support@bracu.ac.bd or visiting University Building # 2, Level 18.

Before getting started…


Since all the lab tasks require students to write codes in Python to solve the problems, students
must ensure that a proper Python environment and IDE (e.g. Jupyter Notebook) are set up or
have a stable internet connection to use Google Colaboratory - an online Notebook-style IDE for
writing Python codes.

Jupyter Notebook:
Tutorial: https://www.youtube.com/watch?v=_GQd1jwH0A4

Download Link: https://www.anaconda.com/products/distribution

Google Colaboratory:
Link: https://colab.research.google.com/

Slack: https://join.slack.com/t/cse110summer2023/signup

buX:
https://bux-home.bracu.ac.bd/courses/course-v1:buX+CSE110+2023_Summer/abo
ut
Task 1
Write a Python program that prints "hello world" in a console.

Sample Input Sample Output

hello world

Task 2
Write a Python program that prints the summation of 54 and 56. The program must use Python
operators and numbers but not use any variables.

Sample Input Sample Output

110

Task 3
Write a Python program that assigns the values "Summer" and 2023 to variables `season` and
`year` respectively. Then, print the values of both variables in separate lines.

Sample Input Sample Output

Summer
2023

Task 4
Write a Python program that reads the user's name and prints it back as shown in the examples
below.

Sample Input Sample Output

John Your name is John

Albert Your name is Albert


Task 5
Write a Python program that reads two integers M and N respectively and finds the value of
𝑁
M^N (or 𝑀 ) and prints the value exactly as shown in the examples below. Your code should
work correctly for any other sample inputs.

Sample Input Sample Output

2 2^3: 8
3

10 10^3: 1000
3

Task 6
A sailor has a boat known as Téssares Boat, which has four corners. The boat is capable of
carrying goods of any weight as long as there is equal distribution of loads on each corner of the
boat - the center area has been occupied by the engine. The sailor needs your help to know the
maximum amount of weight he can carry in each shipment.

Write a Python program that reads the total weight of the shipment and prints the maximum load
(or weight) the boat can take from the given shipment. We can assume that the weight of each
good is exactly 1 unit, therefore, the weight of 5 units means there are 5 (loose) items in the
shipment.

Sample Input Sample Output

9 8

11 8

23 20
Task 7
Write a Python program that reads 3 integers A, B, and C respectively, and then reads a floating
point number D. After reading, the program should print the result (as int) using the given
formula below.

𝐶 𝐷
Formula110: 𝐴 +𝐵*𝐴− 3

Sample Input Sample Output

2 267
6
8
1.3

9 907
100
1
3.7

88 2022
22
1
3.3
Task 8
Write a python program that takes an integer from the user which represents the number of
chocolates that he/she has. He/She decided to distribute the chocolates equally among 3 friends,
keeping the remaining chocolates for him/herself. Find out the number of chocolates each friend
will receive and the number of chocolates that will be remaining.

Sample Input 1:

50

Sample Output 1:

Each friend will receive 16 chocolates

The number of remaining chocolates is 2

Sample Input 2:

90

Sample Output 2:

Each friend will receive 30 chocolates

The number of remaining chocolates is 0


Optional (9 - 11) [Ungraded]
These tasks are just for practice. No marks will be deducted for not
completing them and no bonus marks will be given for solving them.
Just try and practice these problems.

Task 9
Write a Python program that reads two values M and N from the user respectively and prints the
result by joining (concatenating) them in a bottom-up approach as shown in the following
example.

Sample Input Sample Output

5 25
2

Hello WorldHello
World

Python 3Python
3

Task 10
Write a Python program that takes an integer, a float, and another integer number as input from
the user and prints the result as shown below. At first, add the first integer number to the float
and then concatenate the third input integer number.

Sample Input Sample Output

3 The inputs: 3, 11.57, 7


11.57
7 The result is 14.577

33 The inputs: 33, 1.9, 753


1.9
753 The result is 34.9753
Task 11
Write a Python program that reads an integer and prints "True" if the number is even, otherwise,
"False". [Need concept of branching/conditional statements/if-else statements to solve this.
These topics may not have been discussed in class yet. Try to solve it if you can.]

Sample Input Sample Output

7 False

0 True

-11 False

-26 True

Next lab
Branching

You might also like