pierian-data / complete-python-3-bootcamp Goto Github PK
View Code? Open in Web Editor NEWCourse Files for Complete Python 3 Bootcamp Course on Udemy
Course Files for Complete Python 3 Bootcamp Course on Udemy
Any chance of writing an explanation of the 'with' method/function (?) that you use in the video please? I got a little lost there. (Complete-Python-3-Bootcamp/00-Python Object and Data Structure Basics/08-Files.ipynb)
#can i use this code??
def player_input():
value=input('make a choice:')
condition=True
while condition:
if value=='X':
print('you have choosen {}'.format(value))
return ('X','O')
break
elif value=='O':
print('you have choosen {}'.format(value))
return ('O','X')
break
else:
condition=False
while not condition:
value=input('please make a choice again between X or O:')
condition=True
When I first went on to Jupyter Notebook it worked fine, but after a few lessons of using it the code would not work at all and it would show: In[*]. No matter what code I put in it just wouldn't work. I tried restarting the Kernel, deleting other files, everything! I eventually went on to Jupyter lab but it did the exact same thing that Jupyter Notebook did. Can someone please help me out with this?
I like to confirm if i can download the video to enable me watch the video training without using my data
I am struggling tiwrite the code down it won't allow me to write anything
When attempting to open: 14-Advanced Python Objects and Data Structures/04-Advanced Dictionaries.ipynb I get an error that says: "Sorry, something went wrong. Reload?"
All other files have opened for me, thus far.
I am unable to write the code.How do I redirect it to Jupyter notebook?
Getting error list indices must be integrats or slices, not str
When trying to assign marker to board position
below line of code is goin in loop...what mistake i am makingg
def player_input():
player1 = ''
player2 = ''
while (player1 != 'X' or player1 != 'O'):
player1 = input('Please pick a marker X or O')
if player1 == 'X':
player2 == 'O'
else :
player2 == 'X'
Hi, everyone.
Can someone please explain to my what the expression "nums[i:i+2]" do in the find_33 problem.
The solution is like follows:
def has_33(nums):
for i in range(0, len(nums)-1):
# nicer looking alternative in commented code
#if nums[i] == 3 and nums[i+1] == 3:
if nums[i:i+2] == [3,3]:
return True
return False
Hi, I don't know why I can't type in cells.
I use chrome.
thanks
%%writefile mylife.txt
hello ord
hello cazy
hello weezy & zak
hello hemy & max
mylife=open('mylife.txt')
mylife.read()
mylife.seek(0)
mylife.read()
contents=mylife.seek(0)
mylife.readlines()
['hello ord \n', 'hello cazy\n', 'hello weezy & zak \n', 'hello hemy & max \n']
#i need above lines in new lines
Python course
Please Give Me Solution
I had a question about the slide in the course that mentions the global function. The example was like this:
x = 50
def func(x):
print (f'X is {x}')
# local reassignment!
x = 200
print (f'I just locally changed x to {x}')
func(x)
--> X is 50
I just locally changed x to 200.
print(x)
--> 50
I totally get all of this. What happens next confuses me, when the global function is added.
x = 50
def func(x):
global x <------ shouldn't this be overwriting x as 200 everywhere?
print (f'X is {x}')
# local reassignment!
x = 200
print (f'I just locally changed x to {x}')
func(x)
--> X is 50 <------ so this should be 200? Why is it still 50?
I just locally changed x to 200.
print(x)
--> 200 <------- and this should also be 200?
Hope that's clear! Thank you so much!
perform aggregation,grouping,selfjoins & nested queries on database tables .
please give a code of this.
Hello
I have been asking for assistance on my local kernel disconnecting for the past month. I am attempting to finish my certificate with the Udemy Python 3 course Zero to Hero. It seems when I run input functions ex:
def play_game():
start_game = str(input("Ready..? Yes or No: ")).
A hourglass appears next to my Jupyter notebook. After I cannot run any code. The only solution I have found is to restart the kernel, but short thereafter if I run my input functions it occurs again. This is a very frustrating issue that has set me back a couple weeks from my anticipated end date for my Udemy course. I have no got any reliable feedback and would greatly appreciate some help with issue.
Thanks,
Thomas
Trying to do the functional practice exercise but it won't allow me to make any edits or changes in the coding?
import math
def is_prime2(num):
'''
Better method of checking for primes.
'''
if num % 2 == 0 and num > 2:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
is the program correct, because for ever number it just returns true
I get an error saying, "local variable 'position' referenced before assignment
##ini_dict = {'NYC': ['10.00', '5.00', '2.00'], 'SFO': ['12.00', '4.00', '2.00']} -- Initial dictionary
code to sum the value of each key in dictionary
result = {}
for d in ini_dict:
for k in d.keys(): --> Error str' object has no attribute 'keys'
result[k] = result.get(k, 0) + d[k]
In the 03-Function Practice Exercises.ipynb notebook, Summer f '69 exercise, the instructor posted a long solution as an answer.
Wouldn't it be better to follow this approach instead?
def summer_69(arr):
if (6 not in arr):
print(0)
else:
print(sum((arr[0:arr.index(6)])+(arr[arr.index(9)+1:])))
from IPython.display import clear_output
def display_board(board):
clear_output()
print(board[7]+'|'+board[8]+'|'+board[9])
print(board[4]+'|'+board[5]+'|'+board[6])
print(board[1]+'|'+board[2]+'|'+board[3])
def player_input():
marker = ''
while not (marker=='X' or marker=='0'):
marker = input('Player1 : Do you want to be X or O').upper()
if marker == 'X':
return ('X','O')
else:
if marker =='O':
return ('O','X')
def place_marker(board,marker,position):
board[position]= marker
def win_check(board, mark):
return ((board[7] == mark and board[8] == mark and board[9] == mark) or # across the top
(board[4] == mark and board[5] == mark and board[6] == mark) or # across the middle
(board[1] == mark and board[2] == mark and board[3] == mark) or # across the bottom
(board[7] == mark and board[4] == mark and board[1] == mark) or # down the middle
(board[8] == mark and board[5] == mark and board[2] == mark) or # down the middle
(board[9] == mark and board[6] == mark and board[3] == mark) or # down the right side
(board[7] == mark and board[5] == mark and board[3] == mark) or # diagonal
(board[9] == mark and board[5] == mark and board[1] == mark))
import random
def choose_first():
flip = random.randint(0,1)
if flip==0:
return 'Player1'
else:
return 'Player2'
def space_check(board,position):
return board[position]== ' '
def full_board_check(board):
for i in range(1,10):
if space_check(board,i):
return False
return True
def player_choice(board):
position = 0
while position not in range(1,10) or not space_check(board,position):
position=int(input('choose a position: (1-9) '))
return position
def replay():
choice = input('Play Again? Enter Yes or No')
return choice== 'Yes'.lower()
print('Welcome To Tic Tac Toe!')
while True:
the_board= [' ']*10
player1_marker,player2_marker=player_input()
turn = choose_first()
print(turn+'will go first!')
play_game= input('Ready to play? y or n?')
if play_game== 'y':
game_on = True
else:
game_on = False
while game_on:
if turn == 'Player 1':
display_board(the_board)
position = player_choice(the_board)
place_marker(the_board,player1_marker,position)
if win_check(the_board,player1_marker):
display_board(the_board)
print('Player 1 Has Won')
game_on = False
else:
if full_board_check(the_board):
display_board(the_board)
print('Tie Game!!')
break
else:
turn = 'Player 2'
else:
display_board(the_board)
position = player_choice(the_board)
place_marker(the_board,player2_marker,position)
if win_check(the_board,player2_marker):
display_board(the_board)
print('Player 2 Has Won')
game_on = False
else:
if full_board_check(the_board):
display_board(the_board)
print('Tie Game!!')
break
else:
turn = 'Player 1'
if not replay():
break
cant chose o in milestone project 1 please help, point out my mistake
Hi Pierian-Data,
You asked:
Can you sort a dictionary? Why or why not?
And in your keynote, you mentioned that the dictionary is unordered key-value pairs. I don't think that's true any more in CPython 3.6+ (as an implementation detail) and Python 3.7+ (as a language feature).
This is the mail found in python.org
https://mail.python.org/pipermail/python-dev/2017-December/151283.html
Though python still does not provide the sort
method, we could still "sort" it as it retains insertion order.
sort_dict = lambda d: dict(sorted(d.items()))
The solution that has been provided for the question "Summer of 69" doesn't give the correct solution.
When it is tested with
summer_69([1, 3, 5]) => it is OK but
summer_69([6,1, 3, 5]) => it is not correct.
My solution is ;
def summer_69(arr):
total = 0
start = 0
end = 0
flag = False
for i in range(len(arr)):
if arr[i] == 6:
flag = True
start = i
if arr[i] == 9 and flag:
end = i
total += arr[i]
if start >= 0 and end >= 1:
total = total - sum(arr[start:end+1])
return total
Hi, I encountered this issue when I try to pass in a list object in a function inside another function. I have a game_on() function with all the main code. There I had a pre-defined value(hand) func to calculate hand value comparing to 21. but when I try to pass in player_hand, this error keeps pop out but when I wrote it eslewhere. it is fine. Please see attached screenshot:
If I try to do the same at a new block, there will be no message as 'str' object is not callable. It would work as it should be.
Could you advise on the issue?
Thanks!
Write a Python function that checks whether a passed string is palindrome or not.
Note: A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.
I have problem. When my string have more than 1 part "Nurses run", y take only first part "Nurses". I don't know why. Can someone help me?
def palindrom(string):
word = string.split(" ")
y = ""
for z in word:
y += z
if y.lower() == y.lower()[::-1]:
print(word)
print(y)
return f" True word = {y.lower()}, palindrom = {y.lower()[::-1]}"
else:
print(word)
print(y)
return f"False word = {y.lower()}, palindrom = {y.lower()[::-1]}"
Is paper_doll('Mississippi') this should be paper_doll('Missippi')?
Where should I write the answer?
Hi everyone
Can anyone help me to return a list when using **kwargs or *args
I have tryied following:
def myfunc(**kwargs):
I=list(kwargs)
for i in I:
if i %2==0:
return i
Please help me out:)
i get this error
%%UsageError: %%writefile is a cell magic, but the cell body is empty.
while i am writing a code of : %%writefile test.txt
Hello,
I was just wondering for the Functions and Methods homework assignment question 5 - multiply all the numbers in a list - are the square brackets used to turn 'numbers' into a list with an unknown number of variables?
e.g.
def multiply(numbers):
total = numbers[0] <----- I don't quite get this bit - why [0]?
for x in numbers:
total *=x
return total
Thanks so much for your help!
####while running this code in python shell, getting invalid syntax in the second line of code
class line:
def__init__(self,coor1,coor2): ### invalid syntax ###
self.coor1=coor1
self.coor2=coor2
def distance (self):
x1,y1=self.coor1
x2,y2=self.coor2
return ((x2-x1)**2 + (y2-y1)**2)**0.5
def slope (self);
x1,y1=self.coor1
x2,y2=self.coor2
return (y2-y1)(x2-x1)
coor1=(3,2)
coor2=(8,10)
myline= line(coor1,coor2)
No download option is available for test .ipnyb or notebook file. How do you perform the test?
Cant understand why am I getting this error?
Thanks for your help.
class Deck:
def __init__self():
self.deck =[]
for i in shapes:
for j in rank:
self.deck.append(card(rank,shapes))
def __str__(self):
return f'The CardDeck is {self.deck}'
def deal(self):
random.shuffle(self.deck)
def deal(self):
self.deck.pop()
test_deck = Deck()
print(test_deck)
this is level 2 problems from function exercise
Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.
sol:
def has_33(nums):
for x in range(0,len(nums)-1):
if nums[x:x+2] == [3,3]:
return True
else:
return False
here, we want to find array contains 3 next to 3.
in slicing we need to put nums[x:x+1]
I think we need to check next position so we need to use x:x+1
but we are using x:x+2
please help me understanding this
def e_e(listing):
d=[]
for a in listing:
if type(a)==str:
d.append(a)
else:
False
return d
my_list=['dragon',1,'ball',2,'zzz']
list(map(e_e,my_list))
It says "temp" not defined after i ran second code
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.