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

Pdfjoiner

The document provides instructions for a Python challenge to create a program that asks a salesperson for their name and monthly sales amount, calculates their 13% commission on sales, and prints a sentence with their name and commission amount. The program combines various concepts learned in Day 2 such as arithmetic operations, data type conversions, string formatting, and rounding to complete the task. Completing the challenge will help celebrate finishing Day 2 content and put newly learned Python skills to use in a simple real-world application.

Uploaded by

avardhineni2
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)
31 views

Pdfjoiner

The document provides instructions for a Python challenge to create a program that asks a salesperson for their name and monthly sales amount, calculates their 13% commission on sales, and prints a sentence with their name and commission amount. The program combines various concepts learned in Day 2 such as arithmetic operations, data type conversions, string formatting, and rounding to complete the task. Completing the challenge will help celebrate finishing Day 2 content and put newly learned Python skills to use in a simple real-world application.

Uploaded by

avardhineni2
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/ 13

TOTAL

print
Python

Statement that when executed shows (or prints) on the screen


the argument inside the parentheses.

display text
Write text characters that should be displayed on the screen
between single or double quotes.
print("Hello world")
>> Hello world

display numbers
The number can stand alone or be the result of a math
expression. We don't use quotation marks in these cases.

print(150 + 50)
>> 200
TOTAL

strings
Python

Strings in Python are a data type made up of sequences of


characters of any type, that make up some text.

concatenation
Union of text strings:
print("Hello" + " " + "world")
>> Hello world

special characters
We can tell the console that the character after the \ symbol
should be treated as a special character.

\" > Print quotes


\n > Separate text on a new line
\t > Print a tab
\\ > Print a backslash
TOTAL

input
Python

Function that allows the user to enter information through the


keyboard when executed, while giving an instruction about the
requested entry. The code will continue to run after the user
performs the action.

input("Write your name: ")


>> Write your name: |

Waiting for user input


(keyboard)

print("Your name is " + input("Write your


name: "))
>> Write your name: Federico
>> Your name is Federico
Day 1 Python Challenge
The most awaited moment of your first day of study has arrived. You are going to create your
first solo program, and you are going to do it applying everything you have learned throughout
this day.

Imagine the situation: Your best friend has started a brewery and has everything ready. His
product is fantastic. It has body, good flavor, good color, and just the right level of foam. But it
lacks an identity. He can't think of a name for his beer that would give it a unique and original
identity.

So, you come to him and say: “Don’t worry. I'm going to create a program that will ask you
two questions and then tell you what to name your beer. It's as simple as that.”

I know that in the real world, we wouldn't need to develop a software just to ask it two
questions. But until we learn a bit more functionality, well, our programs are going to have to
stay in the realm of simplicity. Yet if you're just starting out, this is going to be quite a challenge.

You're going to create Python code that asks your friend to answer two questions that
require a single word each, and then displays those combined words on the screen to
form a creative brand.

You can use any questions you want. The idea is for the outcome to be original,
creative, and even funny. And if you want to add some difficulty to your challenge, I
suggest you try to have the name of the beer printed in quotation marks on the screen.

Remember that there are different ways for the print function to show the quotes without
interrupting the stream, and it's also possible to print out text in at least two lines using line
breaks within the code.

Well, try to do it on your own, and if it gets complicated, don't worry, we will solve it together
in the next lecture.

Cheers and good luck.


TOTAL

data types
Python

In Python we have several data structures, which are


fundamental in programming since they store information and
allow us to manage it.

text (str) numbers booleans


"Python" int 250 True
"750" float 12.50 False

structures mutable ordered duplicates


lists [ ]
tuples ( )
sets { }
dictionaries { } * : **
*: In Python 3.7+, there are new features **: key is unique ; value can be repeated
TOTAL

variables
Python

Variables are containers for storing data values of different


types, and (as their name suggest), they can change over the
code's execution. A variable is created the moment you first
assign a value to it, so you don't need to declare them first.

some examples
country = "Thailand"

name = input('Enter your name: ')


print("Your name is " + name)

num1 = 55
num2 = 45
print(num1 + num2)
>> 100
TOTAL

naming Python

variables
There are conventions and best practices associated with
naming variables in Python. They are aimed towards
readability and maintainability of the code.

rules
1. Readable: variable name should be relevant to its content
2. Unit: there are no spaces (instead, use underscores)
3. Plain: omit certain language-specific signs, such as ñ, è, ç
4. Numbers: Variable names must not start with numbers
(although we can have them at the end of the variable
name)
5. Symbols: Must not include : " ' , < > / ? | \ ( ) ! @ # $ % ^ & * ~
-+
6. Keywords: we do not use Python reserved words
TOTAL

integers & floats


Python

There are two basic numeric data types in Python: int and
float. Like any variable in Python, its type is defined the
moment we assign a value to a variable. You can get the data
type of a variable with the type() function.

int
An integer, positive or negative, without decimals, of
indeterminate length.
num1 = 7
print(type(num1))
>> <class 'int'>

float
Number that can be positive or negative, which in turn
contains one or more decimal places.
num2 = 7.525587
print(type(num2))
>> <class 'float'>
TOTAL

type conversions
Python

Python performs implicit data type conversions automatically


to operate on numeric values. If you want to specify the data
type, you can use constructor functions.

int(var)
>> <class 'int'> Setting the data type as integer

float(var)
Setting the data type as float
>> <class 'float'>
TOTAL

formatting strings
Python

We have two main tools to mix static text and variables into
strings:

Format function: enables you to concatenate parts of a


string at desired intervals. Multiple pairs of curly braces can
be used while formatting the string. Python will replace the
placeholders with values in order.

print("My car is {}, and it's license


plate is {}".format(car_color,plate))

formatted string literals (f-strings): the newer way to


format strings (Python 3.8+), with a simple and less
verbose syntax: just include f at the beggining of the string
and call the variables inside curly brackets.

print(f"My car is {car_color} and it's


license plate is {plate}")
TOTAL

arithmetic
Python

operators
Arithmetic operators are used with numeric values to perform
common mathematical operations:

Addition: +

Subtraction: -

Multiplication: *

Division: /

Floor division: //
useful for detecting
Modulus: % even values :)

Exponentiation: **
just a special case
Square root: **0.5 of exponentiation
TOTAL

round
Python

Rounding makes it easier to read calculated values by limiting


the number of decimal places displayed on the screen. It also
allows us to approximate decimal values to the nearest integer.

round(number,ndigits)
number to be number of
rounded decimals to use
(default is 0 = int)

examples
print(round(100/3))
>> 33

print(round(12/7,2))
>> 1.71
Day 2 Python Challenge
Congratulations: You've finished learning all the content of Day 2, and now you're able to
create a slightly more complex program.

You already know how to do things like mathematical operations, data type conversions, string
formatting and rounding. Let’s celebrate with a new challenge.

The situation is this: You work in a company where salespeople receive 13%
commissions on their total sales, and your boss wants you to help the salespeople
calculate their commissions by creating a program that asks them their name and
how much they've sold this month.

Your program will answer them with a sentence that includes their name and the
amount of commissions they are entitled to.

Now, this is not a complex program, but that's okay, you're still learning. Even though what
you have learned so far is very simple, putting it all together in one program can make your new
skills get a little bit messy.

A couple of guidelines:

 This program should start by asking the user for things. So, you're going to need to use
input to receive user input, and you should use variables to store that input. Remember
that user inputs are stored as strings, so you should convert one of those inputs to float
to be able to do operations on it.
 And what operation do you need to do? Well, calculate 13% of the number that the user
has entered. That is, multiply the number by 13, then divide by 100.
 It would be good to print the result on the screen, so make sure this information has no
more than two decimals, so it is going to be easy to read. Then, organize all that in a
string that you would format. Remember, we learned two ways to do it, and any of them
is valid.

All right, go on. Try to solve it. And if it gets complicated, Federico will do it with you in the next
lesson.

Go ahead and good luck.

You might also like