My First Learning of Python


Python Basic Understanding_1
In [9]:
print ("Hello World")
print ("Hello Again")
print ("I like typing this.")
print ("This is fun.")
print ('Yay! Printing.')
print ("I'd much rather you 'not'.")
print ('I "said" do not touch this.')
Hello World
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
In [10]:
#how to write a comment out 
In [12]:
print ("I could have code like this.") # and the comment after is ignored
# print "This won't run."
print ("This will run.")
I could have code like this.
This will run.
In [21]:
print ("Hens", 25 + 30 / 6)
print ("Roosters",  100 - 25 * 3 % 4)
print ("Now I will count the eggs:")
print (3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
print (3 + 2 < 5 - 7)
print ("What is 3 + 2?", 3 + 2)
print ("Is it greater?", 5 > -2)
Hens 30.0
Roosters 97
Now I will count the eggs:
6.75
False
What is 3 + 2? 5
Is it greater? True
In [23]:
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven

print ("There are", cars, "cars available.")
print ("There are only", drivers, "drivers available.")
print ("There will be", cars_not_driven, "empty cars today.")
print ("We can transport", carpool_capacity, "people today.")
print ("We have", passengers, "to carpool today.")
print ("We need to put about", average_passengers_per_car, "in each car.")
There are 100 cars available.
There are only 30 drivers available.
There will be 70 empty cars today.
We can transport 120.0 people today.
We have 90 to carpool today.
We need to put about 3.0 in each car.
In [45]:
my_name = 'Soham Chowdhury'
my_age = 28 # not a lie
my_height = 173 # cms
my_weight = 84 # kgs
my_eyes = 'Brown'
my_teeth = 'White'
my_hair = 'Black'


print ("Let's talk about %s." % my_name)
print ("He's %d cms tall." % my_height)
print ("He's %d kgs heavy." % my_weight)
print ("He's got %s eyes and %s hair." % (my_eyes, my_hair))
print ("His teeth are usually %s depending on the tea." % my_teeth)

print ("If I add %d, %d, and %d I get %d." % (my_age, my_height, my_weight, my_age + my_height + my_weight))
Let's talk about Soham Chowdhury.
He's 173 cms tall.
He's 84 kgs heavy.
He's got Brown eyes and Black hair.
His teeth are usually White depending on the tea.
If I add 28, 173, and 84 I get 285.
In [54]:
x = "There are %d types of people." % 2
Introvert = "Introvert"
are_not = "are not"
y = "Those who are %s and those who %s." % (Introvert, are_not)

print (x)
print (y)


print ("I said: %r." % x)
print ("I also said: '%s'." % y)

solution = False
Fact_evaluation = "Isn't that a fact?! %r"

print (Fact_evaluation % solution)

w = "This is the left side of..."
e = "a brain with a right side."

print (w + e)
There are 2 types of people.
Those who are Introvert and those who are not.
I said: 'There are 2 types of people.'.
I also said: 'Those who are Introvert and those who are not.'.
Isn't that a fact?! False
This is the left side of...a brain with a right side.
In [60]:
print ("Baba black sheep have you any wool")
print ("His hair was white as %s." % 'snow')

print ("." * 12) # what'd that do?


end1 = "V"
end2 = "a"
end3 = "d"
end4 = "a"
end5 = "P"
end6 = "a"
end7 = "v"

print (end1 + end2 + end3 + end4),
print (end5 + end6 + end7)
Baba black sheep have you any wool
His hair was white as snow.
............
Vada
Pav
In [67]:
formatter = "%r, %r, %r, %r"

print (formatter % (1, 2, 3, 4))
print (formatter % ("one", "two", "three", "four"))
print (formatter % (True, False, False, True))
print (formatter % (formatter, formatter, formatter, formatter))

print (formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
))
1, 2, 3, 4
'one', 'two', 'three', 'four'
True, False, False, True
'%r, %r, %r, %r', '%r, %r, %r, %r', '%r, %r, %r, %r', '%r, %r, %r, %r'
'I had this thing.', 'That you could type up right.', "But it didn't sing.", 'So I said goodnight.'
In [72]:
days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"


print ("Here are the days: ", days)
print ("Here are the months: ", months)

print ("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
""")
Here are the days:  Mon Tue Wed Thu Fri Sat Sun
Here are the months:  Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.

In [75]:
smelly_cat = "\tI smelled in."
asian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."
Groceries = """
I'll do a list:
\t* Dog food
\t* Bread
\t* Soft Drinks\n\t* Shampoo
"""
print (smelly_cat)
print (asian_cat)
print (backslash_cat)
print (Groceries)
 I smelled in.
I'm split
on a line.
I'm \ a \ cat.

I'll do a list:
 * Dog food
 * Bread
 * Soft Drinks
 * Shampoo

In [80]:
print ("How old are you?"),
age = input()
print ("How tall are you?"),
height = input()
print ("How much do you weigh?"),
weight = input()

print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight))
How old are you?
28
How tall are you?
172
How much do you weigh?
84
So, you're '28' old, '172' tall and '84' heavy.
In [82]:
age = input("How old are you? ")
height = input("How tall are you? ")
weight = input("How much do you weigh? ")

print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight))
How old are you? 28
How tall are you? 173
How much do you weigh? 84
So, you're '28' old, '173' tall and '84' heavy.
In [91]:
from sys import argv
script,a,b = argv

print ("The script is called:", script)
print ("Your first variable is:", a)
print ("Your second variable is:", b)
The script is called: C:\Users\Sohan\Anaconda3\lib\site-packages\ipykernel_launcher.py
Your first variable is: -f
Your second variable is: C:\Users\Sohan\AppData\Roaming\jupyter\runtime\kernel-de8571b8-d556-455c-846d-c9794086d770.json

Comments

Popular posts from this blog

Pandas Library

Exercise 2 - 3

Matplot LIbrary