Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Loop and list in python

Rating
-
Sold
-
Pages
19
Uploaded on
06-03-2025
Written in
2023/2024

This python notes is mainly focus on how to use loop,list and tuple in python cell.

Institution
Course

Content preview

Ternary operations
I don’t assume you’re familiar with other programming languages,
but we need to mention this for those readers who are familiar with other languages.
Many languages have a shorthand way of doing if . . . else all on one line
of code.
If there are three condition we can use “if, elif,else” as
age = int(input(‘enter your age ’))
if age < 20:
print("don't be so childish")
elif 60>age>20:
print("Enjoy your days")
else:
print("Save your strength")
Output
enter your age 36
Enjoy your days

,Looping in python: -
Let us create a table showing the variation of height and range of a projectile with
which is projected at an angle 30 degree with vertical with initial speed 5 m/s.
To do that we have to solve (h=u*cos(a)*t-0.5*g*t**2) and (R=u**2*sin(2*a)/g), where
g=9.8 m/s2; a= 30degree angle; ‘h’ is height; and ‘R’ is range.
We can do the job by two ways.
1. Following the regular way i.e. put the value of t in the formulae and find the val
and ‘R’.
2. Or make a program to do the repetitive tedious job by looping the instruction. Wit
time, range.


While loops: -
Our tusk is to create a table containing time data and corresponding height data. Looping means doing a particular jo
again but with some different values of variables. To do the job, let us find, how while loop works.
1
Relation between height and time is given as ℎ = 𝑢 cos 𝜃. 𝑡 − 𝑔𝑡 2 . For some previous values of constant paramete
2
value of t, we will get a value of h. By repeating this process, we can produce a table. So to repeat the stapes we sho
loop.

, Algorithm: from math import *
a=cos(pi/6); b=sin(pi/6);
1. Print the table variables with proper
uv=5.0*a; uh=5.0*b; g= 9.81; t=0.0; dt=0.1; T=2.0*u
indentation.
while t <= T:
2. Assign the values of constants at t=0 h=-uv*t+0.5*g*t**2
s. R=2.0*uh*uv/g
3. Assign the minimum value of time print('at time %0.2f s, Hight of object %3.2f in m an
(independent variable). %2.2f m'%(t,h,R))
4. Assign the step of increment. t=t+dt
5. Write down the condition or upper
output
bound for reptation using while at time 0.00 s, Hight of object 0.00 in m and Range
statement. at time 0.10 s, Hight of object -0.38 in m and Range
6. Formula or relation between variables. at time 0.20 s, Hight of object -0.67 in m and Range
7. Print the values of variables at time 0.30 s, Hight of object -0.86 in m and Range
8. Increase the steps at time 0.40 s, Hight of object -0.95 in m and Range
9. Declare the end of the program. at time 0.50 s, Hight of object -0.94 in m and Range
at time 0.60 s, Hight of object -0.83 in m and Range
at time 0.70 s, Hight of object -0.63 in m and Range
at time 0.80 s, Hight of object -0.32 in m and Range

Written for

Institution
Course

Document information

Uploaded on
March 6, 2025
Number of pages
19
Written in
2023/2024
Type
Class notes
Professor(s)
Sb
Contains
All classes

Subjects

$5.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
gourabmandal

Get to know the seller

Seller avatar
gourabmandal VC
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions