TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Brain Storming techniques in Python
1. Brain Storming Techniques For
Logic Development Using Lists
Tuples Strings And Dictionaries
In Python
2. Brainstorming is an activity
that helps to
What is Brainstorming in Programmming?
• Produce a large number of ideas
• Generate ideas quickly
• Build enthusiasm
• Solve tricky problems
3. Rules of Brainstorming in Class
Defer judgment
Encourage wild ideas
Build on the ideas of others
Stay focused on the topic
One conversation at a time
Facilitate visual thinking
Go for quantity
5. Working with Python Lists
• Program 1: Take a list of 8 elements. Split it into middle and store the
elements in two different lists.
• Find length of the list.
• Run a loop from first
element till the half
while copying to
another list
• Copy the rest to a third
list
Method 1 Method 2
a=[22,33,44,55,66,77,88,99]
l=len(a)
m=l//2
print(a[:m])
print(a[m:])
Requires 2 loops
6. Working with Python Lists
• Program : Delete duplicate values from a tuple
X=[1,2,2,3,4,4,5,5,6,
7,8,8]
i=0
while i<len(x):
j=i+1
while j<len(x):
if
x[i]==x[j]:
del(x[j])
j=j+1
i=i+1
print(x)
Method 1 Method 2
x=(1,2,2,3,4,4,5,5,6,7,8,8)
y=list(set(x))
print(y)
Requires nested
loops
The set() method converts any of
the iterable to a distinct sequence
of iterable elements
7. Zip() :creating a dictionary lookalike from
Tuples
• Program : To group different data values to form tuples.
name=("Preeti", "Asha","Juli", "Kary")
score=(45,34,89,74)
term=("I","II","II","I")
status=("F","F","P","P")
result=zip(name,score,term,status)
print(tuple(result))
8. Swapping: can be used with all the types
• Program: Names of two students have been swapped. Correct them.
Stud_science="Preeti Mathur"
Stud_commerce="Agastya Gupta"
Stud_science,Stud_commerce=Stud_commerce,Stud_science
print("Sience student is",Stud_science)
print("Commerce Student is ",Stud_commerce)
9. Palindrome
• Program : To check if a string is a Palindrome or not.
s=input("Enter String")
y=s[::-1]
if s==y:
print("Palindrome")
else:
print("Not Palindrome")
string=input("Enter a String")
k=len(string)
t=k//2
flag=True
i=0
j=k-1
for m in range(t):
if string[i]!=string[j]:
flag=False
i=i+1
j=j-1
if flag==True:
print("Palindrome")
else:
print("Not a Palindrome")
Method 1 Method 2
10. Join in strings
• Program :Add a space in between all the letters of a string.
s1=input("Enter a String")
s2=" ".join(s1)
print(s2)
11. Strings and slicing: swapping halves
• Program to swap the first and second half of a string.
str=input("Enter a string")
print(str)
l=len(str)
h=l//2
fh=str[:h]
sh=str[h:]
fh,sh=sh,fh
s=fh + sh
print(s)
12. Reverse a string
• Program. Input a string and reverse it
str=input("Enter a string")
st=str[::-1]
print(st)
15. Creating Dictionaries from input
• Program: Create a record of students with marks in two subjects.
d1=dict()
for i in range(4):
name=input("enter name")
m1=int(input("Enter m1"))
m2=int(input("Enter m2"))
d1[name]=[m1,m2]
print(d1)