0% found this document useful (0 votes)
4 views5 pages

Python Variable Types and Operations

gigigu guiogoi gigi popi p[p[

Uploaded by

sanjana pawar
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)
4 views5 pages

Python Variable Types and Operations

gigigu guiogoi gigi popi p[p[

Uploaded by

sanjana pawar
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

Untitled 1

January 10, 2019

In [57]: # [ ] show the type after assigning bucket = a whole number value such as 16
bucket = 16
type (bucket)

Out[57]: int

In [58]: # [ ] show the type after assigning bucket = a word in "double quotes"
bucket = "water"
type (bucket)

Out[58]: str

In [102]: type (3)

Out[102]: int

In [60]: # [ ] Review and run code for adding a variable string and a literal string
shoe_color = "brown"
print ("my shoe color is " + shoe_color)

my shoe color is brown

In [61]: sm_number = 5 + 5
big_number = 134
sm_number + big_number

Out[61]: 144

In [62]: first_name = 'Naina'


first_name + ", always remembers to save the notebook frequently"

Out[62]: 'Naina, always remembers to save the notebook frequently'

In [63]: 35+15

Out[63]: 50

In [64]: X = 10;
Y = 5

1
In [65]: X + Y

Out[65]: 15

In [66]: # [ ] review & run code for Integer addition in variables and in a print function
int_sum = 6 + 7
print(int_sum)

13

In [67]: print(11 + 15)

26

In [68]: # string addition in variables and in print()function


hat_msg = "I do not wear " + "a hat "

print(hat_msg + "at " + "dinner")

I do not wear a hat at dinner

In [69]: "My favorite food is " + "Chicken"

Out[69]: 'My favorite food is Chicken'

In [88]: # [ ] perform Integer addition in the variable named new_msg (add 2 or more Integers)
new_msg = "9 "

# [ ] create and print a new string variable, new_msg_2, that concatenates new_msg + a
new_msg_2 = "Eggs"
print (new_msg + new_msg_2)

9 Eggs

In [91]: print("my number is " + "123")

my number is 123

In [94]: # [ ] review and run the code - then fix any Errors
total_cost = "3" + "45"
print(total_cost)

345

2
In [97]: # [ ] review and run the code - then fix any Errors
school_num = "123"
print("the street number of Central School is " + school_num)

the street number of Central School is 123

In [124]: # [ ] Read and run the code - write a hypothesis for what you observe adding float + i
# [ ] HYPOTHESIS:

type (5)
print (type(3))

print(3.3 + 3)

<class 'int'>
6.3

In [115]: print("where are my socks?")

where are my socks?

In [118]: print ("Save the notebook frequently")

Save the notebook frequently

In [121]: student_name = "Alton"


print(student_name)

Alton

In [125]: # [ ] repair the TypeError


total = "3"
print(total + " students are signed up for tutoring")

3 students are signed up for tutoring

In [127]: "Ram" + "And" + "Shyam"

Out[127]: 'RamAndShyam'

In [129]: new_string = "Hello " + "World!"


print (new_string)

3
Hello World!

In [144]: PriNt("Hello World!")

---------------------------------------------------------------------------

NameError Traceback (most recent call last)

<ipython-input-144-65c3307914da> in <module>()
----> 1 PriNt("Hello World!")

NameError: name 'PriNt' is not defined

In [148]: # the letter 'A'


print(" *")
print(" * *")
print(" *****")
print(" * *")
print("* *")
print()

*
* *
*****
* *
* *

In [150]: print("_ _")


print(" \ /")
print(" \ . . /")
print(" V")
print()

_ _
\ /
\ . . /
V

In [151]: # the letter 'E'


print("***")
print("*")

4
print("***")
print("*")
print("***")
print()

***
*
***
*
***

You might also like