01.PB Python First Steps in Coding Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Lab: First Steps in Coding

Problems for lab exercise for the "Programming Basics" @ SoftUni Global
Submit your solutions to the SoftUni Judge system at: https://judge.softuni.org/Contests/4577

1. Console Program "Hello SoftUni"


Write a console Python program, which prints the text "Hello SoftUni".
1. Start PyCharm

2. Create a new project: New Project


3. Choose an appropriate name and directory, in which to create your project

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 11


4. Create a new file: Right click on the name of the project New  Python File

5. Enter the name of the file:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 11


6. Write the programming code(commands) for Python

7. Write the following code (command for printing the text"Hello SoftUni"):

print('Hello SoftUni')

8. Start the program by pressing: Alt + Shift + F10 or right click in the code field -> Run

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 11


8. At the bottom of the development environment you will get the following result:

Testing in the Judge System


Test your solutions in the online Judge System https://judge.softuni.org/Contests/Compete/Index/4577#0.
Log in with your SoftUni account. A window for submitting solutions for the "Hello SoftUni" task will appear. Copy
the source code from the development environment and paste it into the solution submission box.

Send your solution using the button Submit. You will receive the result within a few seconds in the table with sent
decisions in the judge system:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 11


2. Numbers from 1 to 10
Write a Python console program, which prints the numbers from 1 to 10 each on a new line.
1. Write 10 print() commands, for each of the numbers from 1 to 10.

Testing in the Judge System


Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#1

3. Area of a rectangle
Write a console program that receives two integers (the sides of rectangle a and b) and calculates the area of a
rectangle with these sides.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 5 of 11


Sample Input and Output
Input Output Input Output
5 6
35 48
7 8

Hints and Guidelines


1. Initialize two variables (a and b) and save the values entered in the console
1. Initialize a second variable area in which to save the value for the face of the rectangle obtained by the
formula a * b.
2. Print the resulting result.

Testing in the Judge System


Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#2

4. Converter: inches to centimeters


Write a program that reads a floating-point number from the console and converts it from inches to centimeters. To
do this, multiply the inches by 2.54 (1 inch = 2.54 centimeters).

Sample Input and Output


Input Output Input Output
5 12.7 7 17.78

Caution: depending on the regional settings of the operating system, a decimal point (US settings) may be used
instead of a decimal point (BG settings). If the program expects a decimal point and a decimal place or reverse
number is entered (a decimal point is entered when a decimal point is expected), an error may be made.
We recommend that you change your computer's settings to use a decimal point:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 6 of 11


Testing in the Judge System
Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#3

5. Greetings by Name
Write a program that reads text from the console (person's name) and prints "Hello, <name>! " where <name>
name is entered from the console.

Guidelines
1. First create a new PyCharm file named greeting
2.Create the variable name and keep in it the name you will read from the console using input():

3. Output the console by concatenation (gluing texts):

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 7 of 11


4. Start the program with Ctrl + Shift + F10 or right mouse button -> Run and test with different input examples.

Testing in the Judge System


Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#4

6. Concatenate Data
Write a program that read from the console name, family, age and town and prints the following message: "You
are <firstName> <lastName>, a <age>-years old person from < town>."

Hints and Guidelines


1. Add another file to the current PyCharm project.
2. Enter the input data and save it into variables with the appropriate data type:

3. Print the formatted output:

4. Start the program with Ctrl + Shift + F10 and test with different input examples:

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 8 of 11


Testing in the Judge System
Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#5

7. Projects Creation
Write a program that calculates how many hours it will take an architect to prepare the projects on several
construction sites. The preparation of a project takes three hours.

Input
2 lines are read from the console
1. Name of the architect - text
2. Number of projects to be prepared- integer in the interval [0 … 100]

Output
Print on the console:
 "The architect {architect name} will need {needed hours} hours to complete {projects
count} project/s."

Sample Input and Output


Input Output Input Output

George The architect George will John The architect John will need 27
need 12 hours to complete hours to complete 9 project/s.
4 9
4 project/s.

Testing in the Judge System


Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#6

8. Pet shop
Write a program that calculates the necessary costs for the purchase of food for dogs and cats. Food is shopped at a
pet store, with a pack of dog food priced at 2.50 USD and a pack of cat food costing 4 USD.

Input
2 lines are read from the console:
1. The number of packages of food for dogs – integer in the interval [0… 100]
2. The number of packages of food for cats – integer in the interval [0… 100]

Output
Print on the console:
"{end sum} USD."

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 9 of 11


Sample Input and Output
Input Output Input Output

5 28.5 USD. 13 68.5 USD.


4 9

Testing in the Judge System


Test your solution in the judge system: https://judge.softuni.org/Contests/Compete/Index/4577#7

9. Yard Greening
Sophia has several houses on the Black Sea coast and wants to green the yards of some of them, thus creating a
cozy atmosphere and comfort for its guests. She has hired a company for this purpose.
Write a program that calculates the amount needed for Sophie to pay to the project contractor. The price per
square meter is 7.61 USD including VAT. Because her yard is quite large, the contractor company offers an 18%
discount on the final price.

Input Data
One line is read from the console:
1. Square meters of the landscaped – a floating-point number in the range [0.00 … 10000.00]

Output Data
Two lines are printed on the console:
 "The final price is: {final price of the service} USD."
 "The discount is: {discount} USD."

Sample Input and Output


Input Output Comments

550 The final price is: 3432.11 We calculate the price for landscaping the whole yard:
USD.
550 * 7.61 = 4185.50 USD.
The discount is: 753.39 USD.
We deduct the discount (18% = 0.18) from the total:
0.18 * 4185.5 = 753.39 USD.
We calculate the final price of the service:
4185.50 – 753.39  3432.11 USD.

Input Output Comments

150 The final price is: 936.03 USD. We calculate the price for landscaping the whole yard:
The discount is: 205.47 USD. 150 * 7.61 = 1141.50 USD.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 10 of 11


We deduct the discount (18% = 0.18) from the total:
0.18 * 1141.50 = 205.47 USD.
We calculate the final price of the service:
1141.50 – 205.47  936.03 USD.

Testing in the Judge System


Test your solution in the Judge system: https://judge.softuni.org/Contests/Compete/Index/4577#8

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 11 of 11

You might also like