Python Forum
Converting Pseudocode to Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Pseudocode to Python
#1
Hi all, Im relatively new to the world of python. Im a Biotechnology major who is picking up coding in his own time. A seemingly very helpful pdf often teaches in pseudocode and there was one particular example which I am having trouble with. I will attach it below

GAUSS(n)
sum <- 0
for i <- to n
sum <- sum + i
return sum

The goal of the code is to create a function which adds your chosen number 'n' to every chronological number before it starting from zero. Below is my attempt

def GAUSS(n)
sum = 0
for i in range(0,n):
sum = sum + i
return sum

As I am learning python as a side hobby please feel free to let me know all things I am doing wrong. All because it is a hobby does not mean I dont want to do my best!

Thanks

ncp
Reply
#2
1. Use Code Tags

Would be nice to have sample output.
def gauss(n):
    s = 0
    for i in n:
        s += i
    return s
    
# python way
print(sum(n))
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting python to FileMaker DWolf 6 1,701 Sep-22-2022, 03:40 AM
Last Post: DWolf
  Converting python to c# benahmadi 1 2,652 Oct-22-2019, 09:50 PM
Last Post: micseydel
  converting array to and from string in python 3.7.2 srm 5 6,206 Jul-03-2019, 01:11 PM
Last Post: snippsat
  help with converting C# function to Python korenron 17 11,346 May-19-2019, 10:26 AM
Last Post: Gribouillis
  Converting R code to python mcva 2 12,536 Mar-09-2019, 04:01 PM
Last Post: mcva
  converting from c# to python peper 1 2,960 Jun-12-2018, 05:19 PM
Last Post: micseydel
  converting python script to another version gptura 5 4,747 Mar-13-2018, 12:16 PM
Last Post: gptura
  Resources for converting Python 2.x code to 3.x Luke_Drillbrain 4 5,032 May-03-2017, 06:34 PM
Last Post: snippsat
  Need help converting some code from python 2.7 to 3.5 Blue Dog 3 4,899 Oct-18-2016, 12:30 AM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020