0% found this document useful (0 votes)
10 views

Beginner_Programming_Notes

This document provides beginner programming notes covering Python and C programming concepts. It includes examples of Python's for loop, list manipulation, random number generation, and terminal commands for file management. Additionally, it explains the C function strcmp and provides a simple example using the curses library in Python.

Uploaded by

sidharth amrutha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Beginner_Programming_Notes

This document provides beginner programming notes covering Python and C programming concepts. It includes examples of Python's for loop, list manipulation, random number generation, and terminal commands for file management. Additionally, it explains the C function strcmp and provides a simple example using the curses library in Python.

Uploaded by

sidharth amrutha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Beginner Programming Notes

Python: for loop with range(6)

for i in range(6):
print(i)

# Output: 0 1 2 3 4 5
# range(6) means 0 to 5 (6 excluded)

Python: list.append()

my_list = [1, 2, 3]
my_list.append(4)
print(my_list)

# Output: [1, 2, 3, 4]

Python: random module

import random
print(random.randint(1, 10)) # Random int from 1 to 10
print(random.random()) # Float from 0.0 to 1.0

Python: random.random()

random.random() returns a float between 0.0 and 1.0.


You can scale it:
value = 10 + (20 - 10) * random.random()

C: strcmp()

#include <string.h>
strcmp(str1, str2)
Returns:
- 0 if equal
- <0 if str1 < str2
- >0 if str1 > str2
Beginner Programming Notes

Terminal: Rename a file

mv oldname.txt newname.txt
# Renames oldname.txt to newname.txt

Terminal: Create folder

mkdir my_folder
# Creates a new folder

Terminal: Open Python file

python3 filename.py
# Runs the file with Python 3

Python: curses example (simplified)

import curses

def main(stdscr):
stdscr.addstr(0, 0, 'Hello from curses!')
stdscr.refresh()
stdscr.getkey()

curses.wrapper(main)

You might also like