RAS Python Code Spec
###Spec v0.0.1 TS: 18-03-2023 11:32:11
Variable Naming Format
-
Name each variable meaningfully.
-
Name everything in lower case and space it out with underscores
Example: For a graphics window object,
graphics_window_object = GraphicsWindow()
- Avoid single variable names like a, x or i for most cases (exceptions may be small iterations statements)
Program Format
- Try to make everything come/run under a main() function
- define constants on top followed by container variables
- Write the purpose of the code on top, additionally write who wrote it and the timestamp.
- Tabs over Spaces. Always
- Tabs should be equal to 4 spaces
- Do not make everything OOP-fied (Turn everything into a class)
Example:
"""
program to print first 10 prime numbers
Author: Shatanu
Time 11:50 AM 18-03-2023
"""
""" Checks if given number is prime or not """
def is_prime(number):
div_count = 0
for i in range(1,number+1):
if number%i == 0:
div_count += 1
if div_count == 2:
return True
return False
def main():
prime_count = 10
start = 1
start_number = 1
primes_list = []
while len(primes_list) < prime_count:
if(is_prime(start_number) == True):
primes_list.append(start_number)
start_number += 1
print("The first 10 primes are: ")
print(str(primes_list))
if __name__ == '__main__':
main()