Answers for "create code in python"

5

how to code in python

#if its your first time start with this
print("hello world")
#now learn about input
input("whats your name")
#if statements and variables
run = True
if run == True:
  print("hi")
#now lets combine our knowledge
print("Whats your name")
name = input("")
print("Hello, " + name)
Posted by: Guest on May-04-2021
0

how to generate python code

class CodeGenerator:
    def __init__(self, indentation='t'):
        self.indentation = indentation
        self.level = 0
        self.code = ''

    def indent(self):
        self.level += 1

    def dedent(self):
        if self.level > 0:
            self.level -= 1

    def __add__(self, value):
        temp = CodeGenerator(indentation=self.indentation)
        temp.level = self.level
        temp.code = str(self) + ''.join([self.indentation for i in range(0, self.level)]) + str(value)
        return temp

    def __str__(self):
        return str(self.code)

a = CodeGenerator()
a += 'for a in range(1, 3):n'
a.indent()
a += 'for b in range(4, 6):n'
a.indent()
a += 'print(a * b)n'
a.dedent()
a += '# pointless commentn'
print(a)
Posted by: Guest on October-16-2020

Code answers related to "create code in python"

Python Answers by Framework

Browse Popular Code Answers by Language