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
Document preview thumbnail
Preview 2 out of 6 pages
Exam (elaborations)

Engr 102 - Exam 1 Review

Document preview thumbnail
Preview 2 out of 6 pages

What do variables do? A variable store something (value, object, whatever) What are the rules for variable naming? 1. Can't start with numbers 2. Can't use key words 3. No spaces Place 'good' next to each of the following good variable names. Place 'bad' next to the bad ones: 1. var 2. total_number_of_students_in_the_room_ZACH_210 3. sum 4. Maclaurin’s 5. initial. Position 6. 36_array 7. Big chonk 1. bad (has keyword) 2. bad (too long) 3. bad (keyword) 4. good 5. bad (can't have a period) 6. bad (can't have numbers) 7. bad (starts with upper case, meme name) What would be the following output? a = 21 b = (a + 4) // 7 #division with no remainder c = a % 5 #gives you remainder print(b) print(a) ################### x = 3 y = x x = 4 print(y) 3 1 ##### 3 List the four main data types and some examples of each 1. Strings (bananas, '71', 'Howdy') 2. Integer (3,4,-21,22) 3. Float (4.0, 7.1, -23.45, 100.99) 4. Boolean (True, False) Data type: tuple An immutable container with ordered elements How do you change the type of variable? Typecasting. Use the desired type and then some parenthesis Ex. .float('72.6') return 72.6 List the three main conversion specifiers and write what the code would output 1. .d #substitutes an integer 2. .f #substitutes a float 3. .s #substitutes a string EXAMPLE: List the three main conversion specifiers and write what the code would output print("I told her %d times that I have a %.2f percent success rate with any %s." % (7, 92.8, dog) I told her 7 times that I have a 92.80 percent success rate with any dog What happens when you use the addition operator on two strings? '12' + '12" = ? 1212 How do you get a user to enter a string, integer, float, boolean? 1.String user_string = input("Enter a string: ") 2.Integer user_integer = int(input("Enter a integer: ")) 3.Float user_float = float(input("Enter a float: ")) 4.Boolean = int(input("Enter 0 for false or 1 for true: ")) MATH - Operators 1. + 2. - 3. * 4. / 5. // 6. ** 7. % 1. addition 2. subtraction 3. multiplication

Content preview

Engr 102 - Exam 1 Review
fr fr fr fr fr




Whatfrdofrvariablesfrdo? Afrvariablefrstorefrsomethingfr(value,frobject,frwhatever)
Whatfrarefrthefrrulesfrforfrvariablefrnaming? 1.frCan'tfrstartfrwithfrnumbers
2.frCan'tfrusefrkeyfrwords
3.frNofrspaces
Placefr'good'frnextfrtofreachfroffrthefrfollowingfrgoodfrvariablefrnames.frPlacefr'bad'frnextfrtofrthefrbadfrones:
1.frvar
2.frtotal_number_of_students_in_the_room_ZACH_210
3.frsum
4.frMaclaurin’s
5.frinitial.frPosition
6.fr36_array
7.frBigfrchonk 1.frbadfr(hasfrkeyword)
2.frbadfr(toofrlong)
3.frbadfr(keyword)
4.frgood
5.frbadfr(can'tfrhavefrafrperiod)
6.frbadfr(can'tfrhavefrnumbers)
7.frbadfr(startsfrwithfrupperfrcase,frmemefrname)
Whatfrwouldfrbefrthefrfollowingfroutput?

afr=fr21
bfr=fr(afr+fr4)fr//fr7fr#divisionfrwithfrnofrremainder
cfr=frafr%fr5fr#givesfryoufrremainder
print(b)
print(a)

###################
xfr=fr3
yfr=frx
xfr=fr4
print(y) 3
1
#####
3
Listfrthefrfourfrmainfrdatafrtypesfrandfrsomefrexamplesfroffreach 1.frStringsfr(bananas,fr'71',fr'Howdy')
2.frIntegerfr(3,4,-21,22)
3.frFloatfr(4.0,fr7.1,fr-23.45,fr100.99)
4.frBooleanfr(True,frFalse)
Datafrtype:
tuple Anfrimmutablefrcontainerfrwithfrorderedfrelements
Howfrdofryoufrchangefrthefrtypefroffrvariable? Typecasting.
Usefrthefrdesiredfrtypefrandfrthenfrsomefrparenthesis
Ex.fr.float('72.6')frreturnfr72.6

, Listfrthefrthreefrmainfrconversionfrspecifiersfrandfrwritefrwhatfrthefrcodefrwouldfroutput
1.fr.dfr#substitutesfranfrinteger
2.fr.ffr#substitutesfrafrfloat
3.fr.sfr#substitutesfrafrstring
EXAMPLE:
Listfrthefrthreefrmainfrconversionfrspecifiersfrandfrwritefrwhatfrthefrcodefrwouldfroutput
print("Ifrtoldfrherfr%dfrtimesfrthatfrIfrhavefrafr%.2ffrpercentfrsuccessfrratefrwithfranyfr%s."fr%fr(7,fr92
.8,frdog)
>>>Ifrtoldfrherfr7frtimesfrthatfrIfrhavefrafr92.80frpercentfrsuccessfrratefrwithfranyfrdog
Whatfrhappensfrwhenfryoufrusefrthefradditionfroperatorfronfrtwofrstrings?
'12'fr+fr'12"fr=fr? >>>1212
Howfrdofryoufrgetfrafruserfrtofrenterfrafrstring,frinteger,frfloat,frboolean? 1.Stringfr
user_stringfr=frinput("Enterfrafrstring:fr")

2.Integer
user_integerfr=frint(input("Enterfrafrinteger:fr"))

3.Float
user_floatfr=frfloat(input("Enterfrafrfloat:fr"))

4.Booleanfr=frint(input("Enterfr0frforfrfalsefrorfr1frforfrtrue:fr"))
MATHfr-frOperators
1.fr+
2.fr-
3.fr*
4.fr/
5.fr//
6.fr**
7.fr% 1.fraddition
2.frsubtraction
3.frmultiplication
4.frdivision
5.frfloorfrdivisionfr
6.frexponent
7.frmodulo
RELATIONALfr-frOperatorsfr
1.fr==
2.fr!=fr
3.fr>
4.fr<
5.fr>=
6.fr<= 1.frequal
2.frnotfrequal
3.frgreaterfrthan
4.frlessfrthan
5.frgreaterfrorfrequalfrthan

Document information

Uploaded on
October 21, 2024
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$11.49

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

Sold
1
Followers
0
Items
48
Last sold
1 year ago


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