You are on page 1of 7

C:\Users\shah_\venv\First_Project\Scripts\python.

exe "C:\Program
Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev\pydevconsole.py"
50957 50958
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['C:\\Users\\shah_\\PycharmProjects\\First_Project',
'C:/Users/shah_/PycharmProjects/First_Project'])
PyDev console: starting.
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]
on win32
a=[1,2,3]
a
[1, 2, 3]
a[0]=23
a
[23, 2, 3]
t=(1,2,3)
t
(1, 2, 3)
t]0]=5
File "<input>", line 1
t]0]=5
^
SyntaxError: invalid syntax
t[0]=5
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
len(t)
3
t.index(1)
0
t.count(1)
1
t=(1,2,3,4,1,3,2,2,2,2)
t.count(2)
5
t.append(0)
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'append'
a=[1,2,3,4,1,2,3,4,1,2,3,4]
set(a)
{1, 2, 3, 4}
a=[1,2,3,4,1,2,3,4,1,2,3,4]
set(a) #to check unique values
{1, 2, 3, 4}
b=list(set(a))
b
[1, 2, 3, 4]
a=[1,2,2,3,3,3,3,3,3,3]
b=list(set(a))
b
[1, 2, 3]
a
[1, 2, 2, 3, 3, 3, 3, 3, 3, 3]
set(a)
{1, 2, 3}
v
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'v' is not defined
b
[1, 2, 3]
a=True
a
True
type(a)
<class 'bool'>
1>2
False
2>1
True
2<3
True
2<5
True
2>6
False
a=2
b=2
a==b
True
a>b
False
a>=b
True
a<b
False
a<=b
True
a!=b
False
#less than<
#greater than equal to >=, less than equal to: <=, check equal to: ==, not equal
to: !=
not(a==b)
False
a==b
True
type(a)
<class 'int'>
a=True
type(a)
<class 'bool'>
1<2<3
True
1<2 and 2<3
True
1<2 and 2<3 and 3<4
True
1<2 and 2<3 and 3>4
False
# or when 1 or more condition is true
1<2 and 2<3 or 3>4
True
1<2 or 2<3 or 3>4 or 3>4
True
1>2 or 2>3 or 3>4 or 3>4
False
1>2 and (2>3 or 3>4)
False
1<2 and (2>3 or 3>4)
False
1<2 and (2<3 or 3<4)
True
1<2 or (3>4 and 5<6)
True

''''''
#conditional statement
a=2
b=4
if a==b: (a is equal to b)
do something

else if a is greater than B


do something else

else if a is less than b


do something else
else
if condition:
''''''

a=(input("Whats your name:"))

if a=="george": #by adding colon it will automatic all indent next line
print("welcome george")
# by backspace we get out of the if statement
elif a=="tom":
print("welcome tom")
print("How is your family")
elif a=="don":
print("welcome don")
else:
print("welcome ... Havent met you before")
print("Have a nice day")

Dictionary:

05/20/2018

dict1={"Tom":67,"Harry":89,"don":95,"Sara":89,"Jenny":98}
for key,values in dict1.items(): #go into dictionary, what items it has and print
what ever values it has
print(key)
print(values)

#whos has 1 rank and last rank


dict1={"Tom":67,"Harry":89,"don":95,"Sara":89,"Jenny":98}
t1 = list(dict1.items())
change=[]
print(t1)
for key,values in dict1.items(): #go into dictionary, what items it has and print
what ever values it has
t=(values,key)
change.append(t)#
print(change)
t2=sorted(t1)
print(t2)
change2=sorted(change,reverse=True)
print(change2)

'''
#while loop
while condition # have to meet the condition
operation
line2
line3

'''
a=10
b=0
while b<a:
print(b)
b=b+1

'''
#while loop
while condition # have to meet the condition
operation
line2
line3

'''
a=10
b=0
while True:
print(b)
if b>=a:
break
b=b+1

'''
#while loop
while condition # have to meet the condition
operation
line2
line3

'''
a=10
b=0
while b<a:
b=b+1
if b%2==0:
continue
print(b)
'''
#while loop
while condition # have to meet the condition
operation
line2
line3

'''
a=[1,2,3]
for i in a:
pass # want to do this in future, but dont want to do it now. rarely used

'''
#while loop
while condition # have to meet the condition
operation
line2
line3

'''
# multiples of 3 and break at 33
x=0
while True:
x=x+1
if x==33:
break
if x%3==0:
print(x)
else:
print("Not multiple of 3:",x)
continue
print("blablabla")

a=list(range(1,10))
print(a)

a=["tom","katty","john"]
for count,b in enumerate(a):
print("at value {} the name of the person is {}".format(count,b))

a=["tom","katty","john"]
temp=list(enumerate(a))
print(temp)

for count,b in enumerate(a):


print("at value {} the name of the person is {}".format(count,b))

from random import *


a=list(range(1,101))
print(a)
shuffle(a)
print(a)

##2nd way
import random as r1
a=list(range(1,101))
print(a)
r1.shuffle(a)
print(a)

###game

from random import *


dice=randint(1,6)
print("Lets guess")
print("enter value between 1 to 6")
print("enter 0 to exit")
guess=[]

while True:
x=int(input("Guess what did the dice show:"))
if x==0:break
if x<0 or x>6:
print("enter valid value")
continue
guess.append(x)
if x==dice:break
elif x<dice:
print("Hint: Increase your value")
else:
print("Hint: decrease your value")
if len(guess)>0:
print(" Congrats!!! you guessed right in",len(guess),"attempts")
else:
print("you didnt play")

##
a="hello world"
mylist=[]
for temp in a:
mylist.append(temp)
print(temp)
print(mylist)

##2nd way

a="hello world"
mylist=[temp for temp in a] # temp is a temporary variable
print(mylist)

def samplehello(name1):
print("hello",name1)

samplehello("john")

def samplehello(name1="anonymous"):
print("hello",name1)

samplehello("john")
def getsum(a=0,b=0):
c=a+b
##print("sum of",a,"and",b,"is",c)
print("sum of {} and {} is {}".format(a,b,c))
print(max(3,4))
getsum(3,4)
getsum()

def getsum(a=0,b=0): #defining a function, defining arguments


c=a+b # arguments
return c
##print("sum of",a,"and",b,"is",c)
#print("sum of {} and {} is {}".format(a,b,c))
#print(max(3,4))

a = getsum(3,4)
print(getsum(10,34))

def checksize(a=0,b=0):
if a>=b:
return True
else:
return False

print(checksize(13,13))

###another way of doing is

def checksize(a=0,b=0):
return a>=b
'''
if a>=b:
return True
else:
return False
'''
print(checksize(12,13))

a=[1,2,3]
## for loop
for b in a:
print(b)
## while loop
while x<len(a):
print(a[x])
x=x=1

You might also like