Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 2 fuera de 6 páginas
Examen

Engr 102 - Exam 1 Review

Document preview thumbnail
Vista previa 2 fuera de 6 páginas

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

Vista previa del contenido

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

Información del documento

Subido en
21 de octubre de 2024
Número de páginas
6
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$11.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
1
Seguidores
0
Artículos
48
Última venta
1 año hace


Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes