• # avec cat << EOF

    Posté par . En réponse au message Introduire un script python dans un script shell. Évalué à 3.

    en utilisant l'astuce cat << EOF

    #!/bin/sh
    echo "script python ______________>"
    cat << EOF | python
    # This program adds two numbers
    num1 = 1.5
    num2 = 6.3
    # Add two numbers
    sum = float(num1) + float(num2)
    # Display the sum
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
    num = 7
    # uncomment to take input from the user
    #num = int(input("Enter a number: "))
    factorial = 1
    # check if the number is negative, positive or zero
    if num < 0:
     print("Sorry, factorial does not exist for negative numbers")
    elif num == 0:
     print("The factorial of 0 is 1")
    else:
     for i in range(1,num + 1):
     factorial = factorial*i
     print("The factorial of",num,"is",factorial)
    EOF
    echo voili voilou

    ce qui donne:

    script python ______________>
    The sum of 1.5 and 6.3 is 7.8
    ('The factorial of', 7, 'is', 5040)
    voili voilou

    J'ai pris des exemples au pif