0% found this document useful (0 votes)
30 views7 pages

LAB 3 Final Codes

The document contains examples of using format strings in Python. It demonstrates defining and calling functions, using format strings with different data types like integers, strings, Booleans, and multi-line strings. Examples include formatting output with separators, concatenating strings, and using format specifiers to insert variables into strings. The goal is to practice using format strings to format output in Python.

Uploaded by

sadaankhan1258
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)
30 views7 pages

LAB 3 Final Codes

The document contains examples of using format strings in Python. It demonstrates defining and calling functions, using format strings with different data types like integers, strings, Booleans, and multi-line strings. Examples include formatting output with separators, concatenating strings, and using format specifiers to insert variables into strings. The goal is to practice using format strings to format output in Python.

Uploaded by

sadaankhan1258
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
You are on page 1/ 7

Practice Code LAB#3

1. Defining a Function and then calling it


Def ():
Print()
Def():
Celsius=float(input(“What is the Celsius temperature?”)
Fahrenheit=9/5*celsius
Print(f”{}”)
()

INPUT :

OUTPUT:
2. Format string
age=input(“”)
height=input(“”)
weight=(“”)
print(f”{}”)

INPUT :

age=input("please enter your age=")


height=input("please enter your height=")
weight=input("please enter your weight=")
print(age,height,weight,sep="\n")

OUTPUT :

>>> %Run -c $EDITOR_CONTENT


please enter your age=18
please enter your height=5.7
please enter your weight=58
18
5.7
58
>>>

3.Boolean and Format String


Types_of_people= 10
X= f’There are { types_of_people } of people
Binary=”binary”
Do_not=”don’t”
Y=f”Those who know{} and for those who {}”
print(X)
print(Y)
print(f”I said{X}”)
print(f”I also said: ‘{Y}”)
hilarious=false
joke_evaluation=”isn’t that joke so funny?{}”
print(joke_evaluation.format(hilarious))
w= “This is the left side of the string”
e= “and this is the right side”
print(w+e)

INPUT :

OUTPUT:

4. Format string #2
print("mary had a little lamb.")
print("its fleece was white as{}. ".format(' snow'))
print("."*10)

INPUT :

OUTPUT:

5. Concatenation
End1=”C”
End2=”H”
End3=”E”
End4=”E”
End5=”S
End6=”E”
End7=”B”
End8=”U”
End9=”R”
End10=”G”
End11=”E”
End12=”R”
Print(End1+ End2+End3+ End4+ End5+ End6+ End7+ End8+ End9+ End10+ End11+End12)
INPUT :

End1="I"
End2="N"
End3="D"
End4="E"
End5="P"
End6="E"
End7="N"
End8="D"
End9="E"
End10="N"
End11="T"
print(End1+ End2+End3+ End4+ End5+ End6+ End7+ End8+ End9+ End10+ End11)

OUTPUT:

>>> %Run -c $EDITOR_CONTENT

INDEPENDENT

>>>

6. Formatter
Formatter= “{} {} {} {}”
Print(formatter.format(1,2,3,4)
Print(formatter.format(one, two , three, four)
Print(formatter.format(True, False, False, True)
Print(formatter.format(formatter, formatter, formatter, formatter)
Print(formatter.format(“Try your”,
“own text”,
“here maybe a poem”,
“or a song about fear”,
))
INPUT :
def main () :
formatter= "{} {} {} {}"
name="MUHAMMAD WAQAR KHAN"
print(name)
print(formatter.format(1,2,3,4))
print(formatter.format("one", "two" , "three", "four"))
print(formatter.format(True, False, False, True))
print(formatter.format(formatter, formatter, formatter, formatter))
print(formatter.format("MY NAME",
"IS WAQAR",
"AND I AM",
"18 YEARS OLD",
))
main ()

OUTPUT:

>>> %Run -c $EDITOR_CONTENT


MUHAMMAD WAQAR KHAN
1234
one two three four
True False False True
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
MY NAME IS WAQAR AND I AM 18 YEARS OLD
>>>

7.Format string #3
P=____’=>’
Print(“How old are you?”, end=’’)
Age=input(f’{p}’)
Print(“how tall are you?”, end=’’)
Height=input()
Print(“How much do you weight”, end=’’)
Weight=input()
Print(f”so you are {} old, {} tall and {} heavy”)

INPUT :

OUTPUT:

You might also like