none
Run Python 3 function problem RRS feed

  • General discussion

  • When I try to run the following script in Powershell, it stops on the first print line after the function:

        

    def cheese_and_crackers (cheese_count, boxes_of_crackers):
        print (f"You have {cheese_count} cheeses!")
        print (f"You have {boxes_of_crackers} crackers!")
        print ("Man, that's enough for a party")
        print ("Get a blanket. \n")

    print ("We can just give the function numbers directly")
    cheese_and_crackers(20, 30)

    print ("OR, we can use variables from our script:")
    amount_of_cheese = 10
    amount_of_crackers = 50

    cheese_and_crackers (amount_of_cheese, amount_of_crackers)

    print ("We can even do math inside too:")
    cheese_and_crackers (10 + 20, 5 + 6)

    print ("And we can combine the two, variables and math:")
    cheese_and_crackers (amount_of_cheese + 100, amount_of_crackers + 1000)

    But on "Pythontutor" it works.  The script is from Zed Shaw's book, Learn Python 3 the Hard Way.

    • Changed type jrv Saturday, February 24, 2018 9:10 PM Wrong forum
    • Moved by jrv Saturday, February 24, 2018 9:18 PM Not a PowerShell issue.
    Saturday, February 24, 2018 8:55 PM

All replies

  • Did you notice that this is a PowerShell forum.  Why would you think Python would work in PowerShell.


    \_(ツ)_/

    Saturday, February 24, 2018 8:58 PM
  • Never mind.  Somehow, the script now works in Powershell.  I have no clue why.  There were no changes made that I can recall.
    Saturday, February 24, 2018 9:07 PM
  • Also your Python code has numerous syntax errors.


    \_(ツ)_/

    Saturday, February 24, 2018 9:09 PM
  • Never mind.  Somehow, the script now works in Powershell.  I have no clue why.  There were no changes made that I can recall.

    Ok - I will delete this as it is not a PowerShell issue.


    \_(ツ)_/

    Saturday, February 24, 2018 9:10 PM
  • If you are running Python under PowerShell suing the "Python" command thenit is executing under python and no PowerSHell.

    You need to post in a python forum for assistance.


    \_(ツ)_/

    Saturday, February 24, 2018 9:17 PM