0% encontró este documento útil (0 votos)
10 vistas

Programas Con Python

Cargado por

dadofania2024
Derechos de autor
© © All Rights Reserved
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
10 vistas

Programas Con Python

Cargado por

dadofania2024
Derechos de autor
© © All Rights Reserved
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 6

Listas python

l1 = [1,2,3,2,4]
l2=list(range(2,9,3))
print (l2)
print(len(l1))
print (l1)
l1.append(-2)
print (l1)
l1.count(3)
print (l1.count(2))
l1.insert(0, 1000)
print (l1)
l1.insert(3, 1000)
print (l1)
l1.sort()
print (l1)
l1.reverse()
print (l1)
print(len(l1))
l1.clear()
print (l1)
l3 =[0.0 for i in range(6)]
print (l3)
l3=[]
for i in range(3):
nota=float(input("Digite la nota: "))
l3.append(nota)
print (l3)

código python:

# script.py

from js import document

# Modificar el contenido del elemento con id "output"

document.getElementById("output").innerText = "¡Hola desde un archivo Python


externo usando PyScript!"
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<!-- Incluir PyScript -->

<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css">

<script defer src="https://pyscript.net/alpha/pyscript.js"></script>

</head>

<body>

<p id="mensaje">Hola mundo, estamos en la página html...</p>

<button id="cambiar">Cambiar texto</button>

<py-script>

from js import document

from pyodide import create_proxy # Importa create_proxy

def cambiar_texto(event):

# Seleccionar el elemento por su id

elemento = document.getElementById("mensaje")

# Cambiar el texto dentro del elemento

if elemento:

elemento.innerText = "¡Texto cambiado desde Python!"

else:

print("El elemento con id='mensaje' no se encontró.")

# Asignar el evento click al botón

# Inicializar evento

def inicializar():

boton = document.getElementById("cambiar")

if boton:
callback_proxy = create_proxy(cambiar_texto) # Crea un proxy para la
función

boton.addEventListener("click", callback_proxy) # Usa el proxy

else:

print("El botón con id='cambiar' no se encontró.")

inicializar()

</py-script>

</body>

</html>

f=open('datos1.txt','w')

r='Matemáticas\n'

f.write(r)

r='Física\n'

f.write(r)

r='Química\n'

f.write(r)

f.close()

while True:

nombre=input('Ingrese el nombre del archivo: ')

try:

arch=open(nombre+'.txt','r')

except FileNotFoundError:

print('El archivo no existe')

crear=input('Digite 1 si desea crear este archivo: ')

if crear=='1':

arch=open(nombre+'.txt','w')

else:
continue

break

# -*- coding: utf-8 -*-

"""

Spyder Editor

This is a temporary script file.

"""

while True:

nombre=input('Ingrese el nombre del archivo: ')

try:

arch=open(nombre+'.txt','r')

linea=arch.readline()

linea=arch.readline()

linea=arch.readline()

linea=arch.readline()

print(linea)

arch.close()

except FileNotFoundError:

print('El archivo no existe')

crear=input('Digite 1 si desea crear este archivo: ')

if crear=='1':
arch=open(nombre+'.txt','w')

else:

continue

break

"""

f=open('datos1.txt','r')

r=f.readline()

print(r)

r=f.readline()

print(r)

r=f.readline()

print(r)

r=f.readline()

print(r)

r=f.readline()

print(r)

r=f.readline()

print(r)

r=f.readline()

print(r)

f.close()

"""

"""

f=open('datos1.txt','w')

r='Matemáticas\n'
f.write(r)

r='Física\n'

f.write(r)

r='Química\n'

f.write(r)

r='Programación Básico\n'

f.write(r)

f.close()

"""

También podría gustarte