• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 7 páginas
Examen

Intro to python (OA) practice questions with complete solutions.docx

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

Intro to python (OA) practice questions with complete

Vista previa del contenido

INTRO to python (OA) practice questions
with complete SOLUTIONS
Createaaaaasolutionaathataaacceptsaathreeaaintegeraainputsaarepresentingaatheaanumberaa
ofaatimesaaanaaemployeeaatravelsaatoaaaaajobaasite.aaOutputaatheaatotalaadistanceaatravele
daatoaatwoaadecimalaaplacesaagivenaatheaafollowingaamilesaaperaaemployeeaacommuteaato
aatheaajobaasite.aaOutputaatheaatotalaadistanceaatraveledaatoaatwoaadecimalaaplacesaagiven
aatheaafollowingaamilesaaperaaemployeeaacommuteaatoaatheaajobaasite:


EmployeeaaA:aa15.62aamiles
EmployeeaaB:aa41.85aamiles
EmployeeaaC:aa32.67aamiles
Theaasolutionaaoutputaashouldaabeaainaatheaaformat
Distance:aatotal_miles_traveledaa-aaANS--commuteaa=aa{
aa'EmployeeaaA':aa15.62,aa
aa'EmployeeaaB':aa41.85,aa
aa'EmployeeaaC':aa32.67
}
travelsaa=aa{
aa'EmployeeaaA':aaint(input()),aa
aa'EmployeeaaB':aaint(input()),aa
aa'EmployeeaaC':aaint(input())
}
t_d_taa=aasum(commute[employee]*travels[employee]aaforaaemployeeaainaatravels)
print(f'Distance:aa{t_d_t:.2f}aamiles')

CreateaaaaaPythonaasolutionaatoaatheaafollowingaatask.aaEnsureaathataatheaasolutionaaprod
ucesaaoutputaainaaexactlyaatheaasameaaformataashownaainaatheaasample(s)aabelow,aainclu
dingaacapitalizationaaandaawhitespace.
Task:
Createaaaaasolutionaathataaacceptsaaanaaintegeraainputaarepresentingaaanyaanumberaaofaa
ounces.aaOutputaatheaaconvertedaatotalaanumberaaofaatons,aapounds,aaandaaremainingaao
uncesaabasedaaonaatheaainputaaouncesaavalue.aaThereaaareaa16aaouncesaainaaaaapoundaa
andaa2,000aapoundsaainaaaaaton.
Theaasolutionaaoutputaashouldaabeaainaatheaaformat

Tons:aavalue_1aaPounds:aavalue_2aaOunces:aavalue_3aa-aaANS--oppaa=aa16
topaa=aa2000
ouncesaa=aaint(input())
tonsaa=aaouncesaa//aa(oppaa*aatop)
roaa=aaouncesaa%aa(oppaa*aatop)
poundsaa=aaroaa//aaopp
roaa%=aaopp

, print(f'Tons:aa{tons}')
print(f'Pounds:aa{pounds}')
print(f'Ounces:aa{ro}')

Createaaaaasolutionaathataaacceptsaaanaaintegeraainputaarepresentingaatheaaindexaavaluea
aforaaanyaaanyaaofaatheaafiveaaelementsaainaatheaafollowingaalist:
various_data_typesaa=aa[516,aa112.49,aaTrue,aa"meow",aa("Western",aa"Governors",aa"U
niversity"),aa{"apple":aa1,aa"pear":aa5}]

Usingaatheaabuilt-
inaafunctionaatype()aaandaagettingaaitsaanameaabyaausingaatheaa.nameaaattribute,aaoutputaa
dataaatypeaa(e.g.,aaint",aa"float",aa"bool",aa"str")aabasedaaonaatheaainputaaindexaavalueaaofa
atheaalistaaelement.


Theaasolutionaaoutputaashouldaabeaainaatheaaformat
Elementaaindex_value:aadata_typeaa-aaANS--I_Vaa=aaint(input())
ifaa-1aa<=aaI_Vaa<aalen(various_data_types):
aaelementaa=aavarious_data_typesaa[I_V]
D_T_Naa=aastr(type(element)).split("'")[1]
print(f'aaElementaa{I_V}:aa{D_T_N}')

Createaaaaasolutionaathataaacceptsaaanyaathreeaaintegeraainputsaarepresentingaatheaabas
eaa(b1,aab2)aaandaaheightaa(h)aameasurementsaaofaaaaatrapezoidaainaameters.aaOutputaat
heaaexactaaareaaaofaatheaatrapezoidaainaasquareaametersaaasaaaaafloataavalue.aaTheaaexa
ctaaareaaaofaaaaatrapezoidaacanaabeaacalculatedaabyaafindingaatheaaaverageaaofaatheaatwo
aabaseaameasurements,aathenaamultiplyingaabyaatheaaheightaameasurement.


TrapezoidaaAreaaaFormula:Aaa=aa[(b1aa+aab2)aa/aa2]aa*aah

Theaasolutionaaoutputaashouldaabeaainaatheaaformat
Trapezoidaaarea:aaarea_valueaasquareaametersaa-aaANS--base_1aa=aaint(input())
base_2aa=aaint(input())
heightaa=aaint(input())
areaaa=aa0.5aa*aa(base_1aa+aabase_2)aa*aaheightaa
print(f'Trapezoidaaarea:aa{area:.1f}aasquareaameters')

Createaaaaasolutionaathataaacceptsaafiveaaintegeraainputs.aaOutputaatheaasumaaofaatheaafiv
eaainputsaathreeaatimes,aaconvertingaatheaainputsaatoaatheaarequestedaadataaatypeaapriora
atoaafindingaatheaasum.
Firstaaoutput:aasumaaofaafiveaainputsaamaintainedaaasaaintegeraavalues
Secondaaoutput:aasumaaofaafiveaainputsaaconvertedaatoaafloataavalues
Thirdaaoutput:aasumaaofaafiveaainputsaaconvertedaatoaastringaavaluesaa(concatenate)

Theaasolutionaaoutputaashouldaabeaainaatheaaformat
Integer:aainteger_sum_valueaaFloat:aafloat_sum_valueaaString:aastring_sum_valueaa-
aaANS--input1aa=aaint(input())

Información del documento

Subido en
26 de diciembre de 2024
Número de páginas
7
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$13.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
8
Seguidores
1
Artículos
714
Última venta
2 semanas 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