1/15
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
for stuff in range(5):
print(stuff) 0
1
2
3
4for i in range(5):
if (i==1) or (i==3):
print("hello")hello
hellomyfamily=["Paul", "Chris", "Mary Ann", "Alan", "Stu", "Rose", "Xyla", "Kate", "Peter", "Addy", "Jamey"]
for person in myfamily:
print(person)Paul
Chris
Mary Ann
Alan
Stu
Rose
Xyla
Kate
Peter
Addy
Jameymyfamily=["Paul", "Chris", "Mary Ann", "Alan", "Stu", "Rose", "Xyla", "Kate", "Peter", "Addy", "Jamey"]
i=0
for person in myfamily:
if (i==1) or (i==3):
print(person)
i=i+1Chris
AlanHow would I do the same thing as in Problem 4, but using the construction “for i” followed by some other commands? Write out the full code (we’ll be generous with punctuation).
i=0
for i in range (len(myfamily)):
if (i==1) or (i==3):
print(myfamily[i])
i+=1Explain how you would do the same thing as in Problem 3, but using the construction “while” followed by some other commands? Write out the full code (we’ll be generous with punctuation).
i=0
while i<(len(myfamily)):
print(myfamily[i])
i+=1def f(x):
return(x*x)
a=2
b=f(a)
print("I called the function on the number %f, and it returned %f" %(a,b))I called the function on the number 2.000000 and it returned 4.000000def add10(x):
x+=10
return(x)
for s in range(5):
print(add10(s))10
11
12
13
14students=["Sigourney", "Meredith", "Chung-pei", "Geraldo", "Tuck"]
j=472
for student in students:
j+=1
print("%d %s" %(j, student))473 Sigourney
474 Meredith
475 Chung-pei
476 Geraldo
477 Tuckdef add10(x)
return(x+10)
y=14
samantha=42
print(add10(y))
print(add10(100))
print(add10(samantha))24
110
52Describe what right ascension is.
Right ascension is one of the two coordinates we use to describe the position of stars and galaxies. It's analagous to longitude around the earth. It's measured in hours (24 hours in a circle) or degrees (360 degrees in a circle.)
Describe what declination is.
Declination is one of the two coordinates we use to describe the position of stars and galaxies. It's analagous to latitude around the earth. It's measured in degrees with 0 being on the celestial equator, +90 degrees at the North Celestial Pole, and -90 at the South Celestial Pole.
Describe what redshift is.
Redshift is a phenomenon where electromagnetic radiation (like light) from an object undergoes an increase in wavelength, shifting to the red end of the electromagnetic spectrum. This can be caused by the object moving away from the observer (Doppler effect) or by the expansion of space itself (cosmological redshift).
Describe what magnitude is.
In astronomy, magnitude is a logarithmic measure of the brightness of a celestial object, as seen by an observer. It can refer to apparent magnitude (how bright an object appears from Earth) or absolute magnitude (how bright an object would appear if it were observed from a standard distance of 10 parsecs).
Why would restricting redshift to a number between .3 and .4 (for example) give you a “slice” of the universe?
Redshift is proportional to distance. So if you restrict redshift to between .3 and .4, you're saying you only want to see galaxies that are a certain distance away from us. The notion of a "slice" is a little weird when you consider the whole universe, because then you'd get a sphere of galaxies that were that distance away. But if you consider that you're looking in one particular direction in the sky, all the galaxies in that direction will sort of look like a slice, or a slab.
import pandas as pd
fruits=pd.read_csv('fruits.csv')
print(fruits.fruit)
print(fruits.shape[0])0 apple
1 orange
2 banana
3 blueberry
Name: fruit, dtype: object
4