Use python
message='hello'
print(message)
person= input('what is your
name?')
print('hello,',person)
person = input('in which class
you study')
always prefer giving input with
variable. We can also give
without variable
print('thats nice')
you can put many person
you can put any other thing
name etc In place of person but
you cannot put numbers in
place of person
for lists
thislist =
["apple", "banana", "cherry"]
print(thislist)
print('hello')
i=input('what is your name')
message = 'hi'
print(message,i)
print('how are you',i)
this is for asking like it will ask
how are you (name)
Uses of if input
and
Print
a = input('9_2')
if (a=='>') : print('correct')
else :
print('incorrect')
or we can do if a==’>’
we can remove bracket
prefer to start print from
the next line with space not
from margin. And it is not
compulsory that after if
there is else omly there can
be any code that can work
there and it can define a
variable also that is
included in any code that is
written above but still
defining ex
c=input("tell difficulty
(1,2,3).1 is easy 2 is
medium and 3 is hard")
if c=="1":
a=[Link](1,30);
b=input("fff");print("gt")
print("welcome to guessing
game")
import random
c = input("tell difficulty
(1,2,3).1 is easy 2 is
medium and 3 is [Link]
are only integers")
if c == "1":
a = [Link](1,
30)
b = input("guess any
number between 1 to 30")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
if c == "2":
a = [Link](1,
60)
b = input("guess any
number between 1 to 60")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
if c == "3":
a = [Link](1,
100)
b = input("guess any
number between 1 to 100")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
in if we can do n number of
tasks or multiple tasks not
only one but we have to
give another command from
next line like in the code
above
and if we have to change
the type like to integer or
string etc this etc is telling
about other data types in if
command like in the code
below, d=int(b).if we will
not put it in if command it
will say not defined and
evertime I am doing int b
because evertime b is used
as input it is then
converting in string
print("welcome to guessing
game")
import random
c = input("tell difficulty
(1,2,3).1 is easy 2 is
medium and 3 is [Link]
are only integers")
if c == "1":
a = [Link](1,
30)
b = input("guess any
number between 1 to 30")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
if c == "2":
a = [Link](1,
60)
b = input("guess any
number between 1 to 60")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
if c == "3":
a = [Link](1,
100)
b = input("guess any
number between 1 to 100")
d = int(b)
if d > a:
print("your no is
greater")
if d < a:
print("your no is
smaller")
Data type
Text Type: str
Numeric Types: int, float, complex
Sequence list, tuple, range
Types:
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
Example Data Type Try it
x = "Hello World" str Try it »
x = 20 int Try it »
x = 20.5 float
Converting any type into
another
guess= input ("Make your
guess number " +
str(current_attempt))
like in this code it will
convert current attempt oly
for that guess input only
We can convert any type in
any like ,string into int ,int
in [Link] the code given
below we have converted
str in int
To convert any into any we
have to just put the data
type in front like
A=”hh”
Print(int(a))
Output=hh but now a is int
Print(str(a)) – this code is
used to convert data type
and print also at the same
time without any variable
a=input("give 1 no to add")
b=input("give another no to
add")
c=int(a)+int(b)
print(c)
int(a) will convert a into int
it was a string before but
now it’s a int so it can be
added
we can do it in another way
like
above everything should be
same changes should be
c=int(a)
d=int(b)
e=c+d
print(e)
using e will make it long
or
print(c+D)
remove e
a=input("give 1 no ")
b=input("give another no ")
c=int(a)+int(b)
e=int(a)-int(b)
f=int(a)*int(b)
g=int(a)/int(b)
d=input("want to add or
subtract or multiply")
if d=="+":print(c)
if d=="*":print(f)
if d=='-':print(e)
if d=="/":print(g)
this program will make a
calculator
Print(“gg’+”gh”)
Output= gggh
Print(“hhr”+6+7)
Output= hhr67
M=”ff”
G=”hj”
F=g+M
Print(f)
Output= ffhj
Or
Print(g+M)
But if we will print
Print(“g”+”m”)
Output= gm
a=input("give 1 no ")
b=input("give another no ")
c=int(a)+int(b)
e=int(a)-int(b)
f=int(a)*int(b)
g=int(a)/int(b)
d=input("want to add or
subtract or multiply or
divide")
if d=="+":print(c)
if d=="*":print(f)
if d=='-':print(e)
if d=="/":print(g)
while input("Do you want to
proceed? (y/n): ") == "y":
a = input("Give 1st
number: ")
b = input("Give another
number: ")
a = int(a)
b = int(b)
d = input("Do you want
to add (+), subtract (-),
multiply (*), or divide (/)? ")
if d == "+":
print("Result:", a + b)
if d == "-":
print("Result:", a - b)
if d == "*":
print("Result:", a * b)
if d == "/":
print("Result:", a / b)
while input("Do you want to
proceed? (y/n): ") == "y":
a = input("Give 1st
number: ")
b = input("Give another
number: ")
a = int(a)
b = int(b)
d = input("Do you want
to add (+), subtract (-),
multiply (*), or divide (/)? ")
if d == "+":
print("Result:", a + b)
if d == "-":
print("Result:", a - b)
if d == "*":
print("Result:", a * b)
if d == "/":
print("Result:", a / b)
while means jb in hindi
and they gave input in front
of while because we do not
have to store we only need
to trigger so it could repeat
the program
while input("Do you want to
proceed? (y/n): ") == "y":
in this after input there is
equals to so it means the
input will go first then if
you pressed y then equals
to will be triggered then the
program or if not pressed y
then it break loop then and
we have not given
command for n so it is like
another alphabet only
and we can do this
a=input(“Do you want to
proceed? (y/n):”)
while a==”y”
a = input("Give 1st
number: ")
b = input("Give another
number: ")
a = int(a)
b = int(b)
d = input("Do you want
to add (+), subtract (-),
multiply (*), or divide (/)? ")
if d == "+":
print("Result:", a + b)
if d == "-":
print("Result:", a - b)
if d == "*":
print("Result:", a * b)
if d == "/":
print("Result:", a / b)
then again loop
random and import string
import random
import string
a=[Link](1,900
0)
b=['messi','ronaldo','pekle','
mochi','makae']
f=[Link](b)
c=[Link]([Link]
nctuation)
e=str(a)
d=e+f+c
print("your new password
is",d)
this code is used to make a
password guesser
here random means any
one of them
and string means that it
dosen’t define but is it used
to take all alphabet
punctuation or digits 1to9
it can be used with a code
to print all alphabet digits
and punctua marks but it
print all like if you gave it a
code to print punctuation it
will print all punctu and it
can also be use with
random like it is used above
if you want random see it
from the code above
things about which to be
cautious
a=input("enter the number
of which you want the
table")
b=float(a)
print(a,"*1=",b*1)
print(a,"*2=",b*2)
print(a,"*3=",b*3)
print(a,"*4=",b*4)
print(a,"*5=",b*5)
print(a,"*6=",b*6)
print(a,"*7=",b*7)
print(a,"*8=",b*8)
print(a,"*9=",b*9)
print(a,"*10=",b*10)
c=input("want table of
another no (yes/no)")
while c=="yes":
a=input("enter the number
of which you want the
table")
b=float(a)
print(a,"*1=",b*1)
print(a,"*2=",b*2)
print(a,"*3=",b*3)
print(a,"*4=",b*4)
print(a,"*5=",b*5)
print(a,"*6=",b*6)
print(a,"*7=",b*7)
print(a,"*8=",b*8)
print(a,"*9=",b*9)
print(a,"*10=",b*10)
c=input("want table of
another no (yes/no)")
like in this code see in
print(a,"*1=",b*1)
print(a,"*2=",b*2)
print(a,"*3=",b*3)
print(a,"*4=",b*4)
print(a,"*5=",b*5)
print(a,"*6=",b*6)
print(a,"*7=",b*7)
print(a,"*8=",b*8)
print(a,"*9=",b*9)
print(a,"*10=",b*10)
after =” there should be a
comma else it will show a
error
b=float(a)
print(a,"*1=",b*1)
print(a,"*2=",b*2)
print(a,"*3=",b*3)
print(a,"*4=",b*4)
print(a,"*5=",b*5)
print(a,"*6=",b*6)
print(a,"*7=",b*7)
print(a,"*8=",b*8)
print(a,"*9=",b*9)
print(a,"*10=",b*10)
c=input("want table of
another no (yes/no)")
if we will remove b and in
print instead of b if it is a
then a is not a float or int
and then also it will
multiply but it will multiply
the string
suppose you enterd input
as 5
if b is removed and in print
instead of b if it is a
then
it will do like
print(a,"*1=",b*1)
print(a,"*2=",b*2)
print(a,"*3=",b*3)
print(a,"*4=",b*4)
print(a,"*5=",b*5)
print(a,"*6=",b*6)
print(a,"*7=",b*7)
print(a,"*8=",b*8)
print(a,"*9=",b*9)
print(a,"*10=",b*10)
output
5
55
555
5555
55555
555555
5555555
55555555
555555555
5555555555
Guessing game code
import random
i = [Link](1,50)
print("guess from 1,50
only")
max_attempts = 10
current_attempt = 0
dd=0
cc=input("enter your name
")
while current_attempt <=
max_attempts:
dd=dd+1
guess= input ("Make your
guess number " + str(dd))
# print
(type(current_attempt))
e=int(guess)
print ("Your guess is : "+
guess)
# implement logic
if e == i:
print ("Yay ! you
guessed it correctly
and .The winner is "+cc)
break
elif e > i:
print ("Your guess was
higher !")
else :
print("Your guess was
smaller")
current_attempt =
current_attempt + 1
if
current_attempt==max_att
empts:
print("you exhausted all
your attempts")
print("better luck next
time")
break
#if
current_attempt==max_att
empts:
print("you exhausted all
your attempts")
print("better luck next
time")
print("number guessed
was"+i)
break
webbrowser
import webbrowser
# Open a URL in the default
browser
[Link]("https://
[Link]")
to open a webbrowser new
tab
webbrowser.open_new_tab(
"[Link]
this code for new tab
url =
"[Link]
[Link](url)
this for opening website but
it will open in your laptop
default webbrowser like
chrome edge etc
import webbrowser
a=input("link")
[Link](a)
this ask you for link give
full link and then it will
open
while loop and while
true
while without true is not
infinite and while with true
is [Link] while true is
infinite.
A thing in while true is
infinite and it needs break
and break will trigger when
if is there like
If d==5:
Break
D=is something
And all are in while true
loop
So if break is not there then
with while true this is
infinite loop
a=input("till:")
b=int(a)
d=0
while True:
if d==b:
break
print("*****")
d=d+1
example of while true
loop with break and if
if only triggers break
Turtle graphics
import turtle as t
[Link]("blue")
[Link](75)
[Link](100)
[Link](140)
[Link](100)
[Link](111)
[Link](75)
[Link]