* UDLA~ *
INT~UULI~TIUN TU ~YT~UN
Dra. Ingrid Kirschning
0
[Link]
Or you can INSTALL PYTHON 3 ON YOUR
OWN SYSTEM, follow the steps at this url:
python ·
Depending on your OS, find the latest version available
[Link]
Microsoft VS Code Anaconda
•
•
•
•
•
•
l. At the top of your window find
option: Create a New Notebook
[Link] the name from
"[Link]" to "[Link]"
3. In the open space type: print('Hello
World!')
Save and find the "Run" or "Play"
button to run your code.
See if you get the correct result.
[n] :.o [Link] LJ
DD
DD !'I Translate D Viaj es D UDLAP D Java D YOLOv4 D Tutorfa y Preceptorfa D Programaci6n D Otros G Spot ify Web Player D ACADEM ICO » D Todos los marcadores
1-line comments
start with #
Did you get the
correct results?
If the population in Puebla
is 1,692,181 , how many are
women? (we have the
percentages)
If the population in Puebla
is 1,692,181 , how many are
women? (we have the
percentages)
•
•
W~AT IS A~UMPLITE~
P~UG~AM? ~
A computer program is just text we
write for the purpose of having the
computer translate it into instructions
that the computer will perform after
that.
Programming Language Every language
has it's
To write a program you need to particular
use a programming language. syntax.
~~~00
W~AT IS A~UMPLITE~ P~U~~AM?
Next the computer translates our
text into ls and Os, because this is
what it can work with.
Executed line by line
No matter how complicated the program is, it will
remain a set of instructions that you write in a
programming language which the computer is
going to translate and execute line by line.
•
•
•
•
•
•
•
•
•
•
•
Start
Flowchart
Enter base
length B
Enter height
length H
area = 0.5 * B *
H
print area
End
• What does this
flowchart tell
you?
• what do you
think each
symbol means?
• what process
does it explain?
•
•
Start
Enter base
length B
Enter height
length H
area = 0.5 * B *
H
print area
End
UATATYPES IN PYT~UN
Numbers:
• Start with a digit (0-9), a decimal point (.) or a minus
sign (-): integers, with floating point (float), complex
numbers (end in j - which is the imaginary part of the
number).
• They cannot contain text, more than one decimal
point, nor symbols (for example:$,%).
Words or character strings:
• Any combination of characters.
• Always enclosed in double ( or single ( quotes.
1111
)
11
)
Boolean:
• They take one of two possible values True or False.
A~IT~METI~ UPE~ATU~S
Operator Description Example
+ add 1+1=2
substract 10-1 =9
* multiply 3*5=15
I divide 1012=5
3 modulus {extract the residue 1133=2
if an integer division)
** exponent 3**2=9
II Integer division 11113=3
CUMPA~ISUN UPE~ATU~S
Example (note that spaces Operator Meaning
are put between operator < Less than
and variable or number): <= Less or equal
> Larger than
num = 10 >= Larger or equal
if num > O: Equal to
print("Positive value
11
)
I= Different
•
else: isObject Is an instance of
print("Negative value 11
)
is not Negation of an
instance
~UULEAN UPE~ATU~S IN PYT~UN
Operator Example Meaning
or x or y
Result is True if one, either x or y
-------·
are True
and x and y Result is True if both, x and y
- - - - - - -
are True
not not x Result is the opposite of the
value of x
•
•
⚬
⚬
•
⚬
⚬
•
⚬
⚬
•
monthly_savings =10
num_months = 12
intro = Hello~ How are you?
11 11
# Calculate year_savings
year_savings = monthly_savings * num_months
# Print the type of year_savings
print (type(yea r_savings))
#Assign sum of intro and intro to doubleintro
doubleintro = intro+ intro
print(doubleintro)
•
•
Instructions:
• Copy and run this code. Try to understand the error message.
• Fix the code such that the printout runs without errors; use the
function strO to convert the variables savings and
total_savings to strings.
• Convert the variable pi_string to a float and store this float as a
new variable, pi_float.
savings 100=
total_savings 150 =
print( I started with $ + savings +
11 11 11
and now have $ 11
+
total_savings + Awesome!
11
•
11
)
pi_string = 11
3.1415926 11
#Convert pi_string into float: pi_float
E~~U~ MESSA~E:
Traceback (most recent call last):
File <stdin> line 72, in exceptionCatcher raise exception
11 11
,
File <stdin> line 3361, in run_ast_nodes
11 11
,
if (await self.run_code(code, result, async_=asy)):
File <stdin> line 3458, in run_code
11 11
,
[Link](running_compiled_code=True)
File <stdin> line 2066, in showtraceback
11 11
,
self._showtraceback(etype, value, stb)
File <stdin> line 72, in exceptionCatcher raise exception
11 11
,
File <stdin> line 3441, in run_code
11 11
,
exec(code_obj, self.user_global_ns, self.user_ns)
File <stdin> line 6, in <module>
11 11
,
print( I started with $ +savings+ and now have $ + total_savings +
11 11 11 11 11
Awesome! 11
)
TypeError: can only concatenate str (not int to str 11 11
)
rlXEU ~UUE
savings= 100
total_savings = 150
# Fixed printout
print( I started with $ + str(savings) + and now have $
11 11 11 11
+ str(total_savings) + Awesome~ )
11
•
11
# Definition of pi_string
pi_string = 3.1415926
11 11
#Convert pi_string into float: pi_float
pi_float = float(pi_string)
W~AT INST~LI~TIUN WILL ~~EATE AN
E~~U~?
11
1can add integers, like + str(S) + to strings.
11 11 11
11
1said + ( Hey * 2) + Heyl
11 11 11 11 11
11
The correct answer to this multiple choice exercise is
answer number + 2 11
True+ False