100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Práctica Informática 3

Rating
-
Sold
-
Pages
10
Uploaded on
13-11-2023
Written in
2023/2024

Práctica informática 3 de la asignatura Programación Informática

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
November 13, 2023
Number of pages
10
Written in
2023/2024
Type
Class notes
Professor(s)
Jose
Contains
All classes

Subjects

Content preview

Programación Informática – Grado en Ingeniería Civil


RESUELTA
Práctica 3: Ficheros

Curso 2023/24


1. Objetivos de la práctica
Abrir y cerrar ficheros

Utilizar la E/S de datos mediante ficheros.


2. Ejercicios a resolver
Ejercicio 1. Modifica el ejercicio 1 de la práctica anterior para que la temperatura en grados
Fahrenheit se pida por teclado pero la temperatura en grados Celsius se almacene en
el fichero “celsius.txt”. El programa deberá mostrar además un mensaje por pantalla
indicando que el fichero “celsius.txt“ se ha creado.
A continuación se muestra un ejemplo de ejecución del programa, junto con el contenido
del fichero resultante:
Ejemplo de ejecución
Introduce los grados Fahrenheit: 84
El fichero "celsius.txt" se ha creado
celsius.txt
84.0 grados Fahrenheit son 28.9 grados Celsius

, SOLUCIÓN:

F = float(input("Introduce los grados Fahrenheit: "))
C = 5/9*(F - 32)
fichero = open("celsius.txt","w")
fichero.write(f"{F:.1f} grados Fahrenheit son {C:.1f} grados Celsius")
fichero.close()
print(f"El fichero \"celsius.txt\" se ha creado")



Ejercicio 2. Modifica de nuevo el ejercicio 1 de la práctica anterior para que que la tem-
peratura en grados Fahrenheit se lea del fichero “fahrenheit.txt”. Dicho fichero debe
crearse previamente, introduciendo en el mismo la temperatura Fahrenheit que se quie-
re convertir a grados Celsius. Por ejemplo:




En este caso, la temperatura en grados Celsius se mostrará por pantalla. Por ejemplo,
para el fichero “fahrenheit.txt” anterior se debería mostrar:


SOLUCIÓN:


fichero=open("fahrenheit.txt","r")
F=fichero.readline().rstrip()
fichero.close()
F=float(F)
C = 5/9*(F-32)
print(f"{F:.1f} grados Fahrenheit son {C:.1f} grados Celsius")




Ejercicio 3. Modifica el ejercicio 2 de la práctica anterior para que el salario bruto y neto
se almacenen en el fichero “salario.txt”. Los datos para calcularlo (el número de horas
trabajadas (nh, entero), el precio de la hora (ph, real) y la retención aplicable en tanto
por cien (r, real) se pedirán por teclado. Además, mostrar un mensaje por pantalla que
informe al usuario que se ha creado el fichero de salida.
$3.75
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
DreamBuilder

Also available in package deal

Get to know the seller

Seller avatar
DreamBuilder Universitat Politécnica de Valencia
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
5
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

Frequently asked questions