Module 2 4930

 Daniel Tafmizi

Dr. Friedman

Lis 4930

May 27, 2024

Module 2

Assignment: 

print ('Hello World')
Hello World
String1 = 'Welcome to the Geeks World'
print("String with the use of Single Quotes: ")
print(String1)
String with the use of Single Quotes: 
Welcome to the Geeks World

It seems that the print and string functions work seamlessly. The string
function offers a "playground" for modification and structuring. The print function allows
the user to use the string in their program. The example above shows a simple use case.
String1 holds a string, that is later called in the program. More advanced uses of this can
begin handling user data or allow for manipulation techniques.






Notes:

Run python in cmd - I did not run into much trouble. Initially, I could not link the script file to the cmd. I tried typing "python3" and it directed me to a Microsoft store download. After downloading the MS python, I was able to type "python3" and access python through the cmd interpreter. 

Starting program - I am using the PyCharm IDE. I believe that this section is asking me to set a directory. I have my directory set to a local folder on my PC named, "Lis4930WeeklyAssign".

Compiler - Turns programming language into usable computer language. Translates source to target.

Interpreter - Executes instructions from a programming language.

Strings - String constant; variable that cannot be modified once declared, types include asciii + digits +
punctuation + whitespace. 

Tuple - like a list

dictionary - like a list but with a key that relates to a value

String formatting through Formatter(); allows you to customize string format

format(format_string*args**kwargs) has an internal dictionary, 

vformat(format_stringargskwargs) accesses external dictionary


mini language in format() -

format_spec ::=  [[fill]align][sign][#][0][width][,][.precision][type]
fill        ::=  <any character>
align       ::=  "<" | ">" | "=" | "^"
sign        ::=  "+" | "-" | " "
width       ::=  integer
precision   ::=  integer
type        ::=  "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"

Ex: 

by position

>>> '{2}, {1}, {0}'.format('a', 'b', 'c')
'c, b, a'

by name

'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
'Coordinates: 37.24N, -115.81W'

by attribute

>>> c = 3-5j
>>> ('The complex number {0} is formed from the real part {0.real} '
...  'and the imaginary part {0.imag}.').format(c)
'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.'

by item

>>> coord = (3, 5)
>>> 'X: {0[0]};  Y: {0[1]}'.format(coord)
'X: 3;  Y: 5'

%r vs %s

>>> "repr() shows quotes: {!r}; str() doesn't: {!s}".format('test1', 'test2')
"repr() shows quotes: 'test1'; str() doesn't: test2"

align and width

>>> '{:<30}'.format('left aligned')
'left aligned 

+f vs -f vs f

>>> '{: f}; {: f}'.format(3.14, -3.14)  # show a space for positive numbers
' 3.140000; -3.140000'

dif bases use #

>>> "int: {0:d};  hex: {0:x};  oct: {0:o};  bin: {0:b}".format(42)
'int: 42;  hex: 2a;  oct: 52;  bin: 101010'

>>> '{:,}'.format(1234567890)
'1,234,567,890'

>>> points = 19.5
>>> total = 22
>>> 'Correct answers: {:.2%}'.format(points/total)
'Correct answers: 88.64%'

type specific

>>> import datetime
>>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)
>>> '{:%Y-%m-%d %H:%M:%S}'.format(d)
'2010-07-04 12:15:58'

args - accessed through tuple

kwargs - accessed through dict

       

Comments

Popular posts from this blog

First Day Assignment

Module 10 Assignment

Final Project