-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
112 lines (94 loc) · 3.27 KB
/
application.py
File metadata and controls
112 lines (94 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
print('hello world')
number = 77
print(number)
weight = 150
answer = number + weight
print(answer)
first_name = 'Dan'
last_name = 'Kiss'
print(first_name + ' ' + last_name + ' weights ' + str(weight) + ' lbs')
isFalse = True
print(type('hi'))
number1 = 5
number2 = 2
print(number1 % number2)
sentence = "I'm \n coming home"
print(sentence[0], sentence[-2])
# I and m
sentence2 = 'this is a sentence'
print(sentence2[0:4])
print(sentence2[0:7:2]) #get every second letter starting at 0
print(sentence2[3:]) # get all letters from 3 on
print(sentence2[-2:]) #start from -2 at end and go to real full end
print(sentence2.upper()) # go upper case on self aka on instance of this string
print(sentence2.capitalize()) # cap first letter only
print('234'.isdigit())
print(sentence2.startswith('this'))
print(sentence2.startswith('is', 5)) #does position 5 start with is
sentence3 = 'The sum of 5 + 10 is {0}'.format(50)
print(sentence3)
sentence3 = 'The sum of {0} + {1} is {2}'.format(10, 15, 25) #notice order of args
print(sentence3)
sentence4 = 'abcde'
# sentence4[0] = 'b' # cannot be done
sentence4 = '1' + sentence4[1:]
print(sentence4)
remainder_of_15_div_4 = 15 % 4
print(remainder_of_15_div_4)
print('we have {0} small boxes, {1} large boxes, {2} medium boxes'.format(10,12,12))
# Assignment 3:
"""
Given 2 variables chars and word, write code to move
the data contained in the variable word in the exact middle of
the characters contained in the variable chars and save this
in a new variable called result and print it.
NOTE: chars variable will contain only 4 characters
Example:
---------------
chars = "<<>>"
word = "hello"
result - should contain the following string: <<hello>>
"""
chars = '[[]]'
word = 'cool'
result = chars[:2] + word + chars[2:]
print(result)
# Assignment 4:
"""
Given 2 variables word1 and word2, write code to
print the concatenation of the 2 words omitting the
first_folder letter of the string saved in word1 and the second_folder
letter of the string saved in word2.
Example:
---------------
word1 = "Vehicle"
word2 = "Robot"
result - ehicleRbot
"""
word_section1_assignment4a = 'Computer'
word_section1_assignment4b = 'Truck'
word_section1_assignment4combo = word_section1_assignment4a[1:] + word_section1_assignment4b[0:1] + word_section1_assignment4b[2:]
print(word_section1_assignment4combo)
# Assignment 5:
"""
Given 2 variables chars and word, write code to move
the data contained in the variable word in the exact middle of
the characters contained in the variable chars and save this
in a new variable called result and print it.
NOTE: chars variable can contain any even number of characters.
the len() function can be used to figure out the length of a string
Example:
---------------
chars = "<[<||>]>"
word = "mirror"
result - should contain the following string: <[<|mirror|>]>
"""
chars = "<<[]]]" # this could be a very long string with an even length.
word = "Cool"
# Expected Result Printed: <<[Cool]]]
# Your code below:
print(len(chars))
middle = round(len(chars)/2) #assuming even number given
# note middle below does not include middle number in :middle aka the middle is the cutoff
result5 = chars[:middle] + word + chars[middle:]
print(result5)