Maison développement back-end Tutoriel Python Jour – Programmes de boucles et de modèles imbriqués

Jour – Programmes de boucles et de modèles imbriqués

Dec 26, 2024 pm 08:16 PM

Day - Nested for loop and Pattern Programs

for row in range(5):
    for col in range(5-row):
        print(col+1, end=" ")
    print()
Copier après la connexion
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
Copier après la connexion
for row in range(5):
    for col in range(row+1):
        print(col+1, end=" ")
    print()
Copier après la connexion
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
Copier après la connexion
for row in range(5):
    for col in range(5-row):
        print(5-col, end=" ")
    print()
Copier après la connexion
5 4 3 2 1 
5 4 3 2 
5 4 3 
5 4 
5 
Copier après la connexion
for row in range(5):
    for col in range(row+1):
        print(5-col, end=" ")
    print()
Copier après la connexion
5 
5 4 
5 4 3 
5 4 3 2 
5 4 3 2 1
Copier après la connexion
no=1
for row in range(5):
    for col in range(5-row):
        print(no, end=" ")
        no+=1
    print()
Copier après la connexion
1 2 3 4 5 
6 7 8 9 
10 11 12 
13 14 
15 
Copier après la connexion
for row in range(5):
    for col in range(5-row):
        print((col+1)*(row+1), end=" ")
    print()
Copier après la connexion
1 2 3 4 5 
2 4 6 8 
3 6 9 
4 8 
5 
Copier après la connexion
for row in range(5): 
    for col in range(5-row):
        print((col+1)+(row+1), end=' ')
    print()
Copier après la connexion
2 3 4 5 6 
3 4 5 6 
4 5 6 
5 6 
6
Copier après la connexion
for row in range(5): 
    for col in range(5-row):
        print((col+1)//(row+1), end=' ')
    print()
Copier après la connexion
1 2 3 4 5 
0 1 1 2 
0 0 1 
0 0 
0 
Copier après la connexion
for row in range(5): 
    for col in range(5-row):
        print((row+1)-(col+1), end=' ')
    print()
Copier après la connexion
0 -1 -2 -3 -4 
1 0 -1 -2 
2 1 0 
3 2 
4
Copier après la connexion
for row in range(5): 
    for col in range(5-row):
        print((row+1)-(col+1)+5, end=' ')
    print()
Copier après la connexion
5 4 3 2 1 
6 5 4 3 
7 6 5 
8 7 
9
Copier après la connexion
for row in range(5): 
    for col in range(5-row):
        print((row+1)+(col+1)-1, end=' ')
    print()
Copier après la connexion
1 2 3 4 5 
2 3 4 5 
3 4 5 
4 5 
5 
Copier après la connexion
for row in range(5):
    for col in range(5-row):
        print(col,end=' ')
    print()
Copier après la connexion
0 1 2 3 4 
0 1 2 3 
0 1 2 
0 1 
0 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    print()
Copier après la connexion
1 2 3 4 
1 2 3 
1 2 
1 

Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    print("*" , end=" ")
    print()
Copier après la connexion
1 2 3 4 * 
1 2 3 * 
1 2 * 
1 * 
* 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    for col in range(5):
        print("*" , end=" ")
    print()
Copier après la connexion
1 2 3 4 * * * * * 
1 2 3 * * * * * 
1 2 * * * * * 
1 * * * * * 
* * * * * 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    for col in range(5):
        print(col, end=" ")
    print()
Copier après la connexion
1 2 3 4 0 1 2 3 4 
1 2 3 0 1 2 3 4 
1 2 0 1 2 3 4 
1 0 1 2 3 4 
0 1 2 3 4 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(5):
        print(col+1, end=" ")
    print()
Copier après la connexion
        1 2 3 4 5 
      1 2 3 4 5 
    1 2 3 4 5 
  1 2 3 4 5 
1 2 3 4 5 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(col+1,end=' ')
    print()
Copier après la connexion
        1 
      1 2 
    1 2 3 
  1 2 3 4 
1 2 3 4 5 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print("", end=' ')
    for col in range(row+1):
        print(col+1,end=' ')
    print()
Copier après la connexion
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(5-col,end=' ')
    print()
Copier après la connexion
        5 
      5 4 
    5 4 3 
  5 4 3 2 
5 4 3 2 1
Copier après la connexion
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(5+col-row,end=' ')
    print()
Copier après la connexion
        5 
      4 5 
    3 4 5 
  2 3 4 5 
1 2 3 4 5 
Copier après la connexion
name='ABCDE'

for row in range(len(name)):
    for col in range(row+1):
        print(name[col], end=" ")
    print()
Copier après la connexion
A 
A B 
A B C 
A B C D 
A B C D E 
Copier après la connexion
name='PRITHA'

for row in range(len(name)):
    for col in range(6-row):
        print(name[col], end=" ")
    print()
Copier après la connexion
P R I T H A 
P R I T H 
P R I T 
P R I 
P R 
P 
Copier après la connexion
for row in range(5):
    for col in range(5-row):
        print((col+1)%2, end=" ")
    print()
Copier après la connexion
1 0 1 0 1 
1 0 1 0 
1 0 1 
1 0 
1 
Copier après la connexion
for row in range(5):
    for col in range(5-row):
        print(((col+1)+(row))%2, end=" ")
    print()
Copier après la connexion
1 0 1 0 1 
0 1 0 1 
1 0 1 
0 1 
1 
Copier après la connexion

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

Video Face Swap

Video Face Swap

Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Comment éviter d'être détecté par le navigateur lors de l'utilisation de Fiddler partout pour la lecture de l'homme au milieu? Comment éviter d'être détecté par le navigateur lors de l'utilisation de Fiddler partout pour la lecture de l'homme au milieu? Apr 02, 2025 am 07:15 AM

Comment éviter d'être détecté lors de l'utilisation de FiddlereVerywhere pour les lectures d'homme dans le milieu lorsque vous utilisez FiddlereVerywhere ...

Comment enseigner les bases de la programmation novice en informatique dans le projet et les méthodes axées sur les problèmes dans les 10 heures? Comment enseigner les bases de la programmation novice en informatique dans le projet et les méthodes axées sur les problèmes dans les 10 heures? Apr 02, 2025 am 07:18 AM

Comment enseigner les bases de la programmation novice en informatique dans les 10 heures? Si vous n'avez que 10 heures pour enseigner à l'informatique novice des connaissances en programmation, que choisissez-vous d'enseigner ...

Comment obtenir des données d'information en contournant le mécanisme anti-frawler d'Investing.com? Comment obtenir des données d'information en contournant le mécanisme anti-frawler d'Investing.com? Apr 02, 2025 am 07:03 AM

Comprendre la stratégie anti-rampe d'investissement.com, Beaucoup de gens essaient souvent de ramper les données d'actualités sur Investing.com (https://cn.investing.com/news/latest-news) ...

Python 3.6 Chargement du fichier de cornichon MODULENOTFOUNDERROR: Que dois-je faire si je charge le fichier de cornichon '__builtin__'? Python 3.6 Chargement du fichier de cornichon MODULENOTFOUNDERROR: Que dois-je faire si je charge le fichier de cornichon '__builtin__'? Apr 02, 2025 am 06:27 AM

Chargement du fichier de cornichon dans Python 3.6 Erreur d'environnement: modulenotFounonError: NomoduLenamed ...

Quelle est la raison pour laquelle les fichiers de pipeline ne peuvent pas être écrits lors de l'utilisation du robot Scapy? Quelle est la raison pour laquelle les fichiers de pipeline ne peuvent pas être écrits lors de l'utilisation du robot Scapy? Apr 02, 2025 am 06:45 AM

Discussion sur les raisons pour lesquelles les fichiers de pipelines ne peuvent pas être écrits lors de l'utilisation de robots scapisnels lors de l'apprentissage et de l'utilisation de Crawlers scapides pour un stockage de données persistant, vous pouvez rencontrer des fichiers de pipeline ...

See all articles