Giter VIP home page Giter VIP logo

python-programming-exercises's Introduction

Python-programming-exercises

100+ Python challenge programming exercises.

100+ Python Projects Challenge

https://github.com/zhiwehu/100_plus_Python_Projects_Challenge

A simple Python online IDE run in browser.

Hey guys I just made a simple Python online IDE run in browser : https://github.com/zhiwehu/react-python-ide. It's free and opensource. Feel free to let me know if you have any issues.

Python comic

Hey guys I just created a comic for learning Python if you like you could see it from here: https://zhixinfuture.com For now I just use Chinese if you like I could use English as well.

Python Comic

python-programming-exercises's People

Contributors

xcao21 avatar zhiwehu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-programming-exercises's Issues

arrangement

it will be better if you separate the answers from the questions and number properly

Solution for question 8 is wrong

Suppose the following input is supplied to the program:
without,hello,bag,world

Then, the output should be:
bag,hello,without,world

The output for the solution is "bag, hello, world, without". Somehow the sorted() function returns "world" < "without". It seems like the sorted() function not try to compare letter by letter.

Q20: Problem is to provide class, answer is a generator function

As in topic: Problem is to provide class, answer is a generator function
You should change "Define a class with a generator which can iterate the numbers" to "Define a generator function which can iterate the numbers"
Or change soultion to provide class with iter() and next() for 2.7 or iter() and next() for 3.0+

Question #20, Level 3

Solution code does not seem to work.
After running the solution provided I get
TypeError:argument to reversed() must be a sequence
I have edited reverse() as reversed().
Haven't found a good solution how to make reversed() sequential. Please help.
Thank you!

Solve a tedious system of equations which cannot be expressed in matrix form

I have two non-linear equations with only two variables which are tedious to solve. Please see below for the equations and conditions:
image1

I'm having difficulty solving this system, is there any way to input this into a solver? I tried solving it manually but it becomes too complex.

Any help would be appreciated, I'm posting it here as a last desperate try to get some hint on how to go about it. Thank you so much.

def equations(p):
    x, y = p
    return ((3*(x**2+y**2))**-1*(x*(x**2+y**2+2.25)*np.sinh((4*m.pi*y*m.e4)/466)+3*x*m.cosh((4*m.pi*y*m.e4)/466)+y*(x**2+y**2-2.25)*m.sin((4*m.pi*x*m.e4)/466)+3*y*m.cos((4*m.pi*x*m.e4)/466))-31.176, 6*(x**2+y**2)**-1*((1+x**2+y**2)*((x**2+y**2+2.25)*m.cosh((4*m.pi*y*m.e4)/466)+3*x*m.sinh((4*m.pi*y*m.e4)/466))+(1-x**2-y**2)*((x**2+y**2-2.25)*m.cos((4*m.pi*x*m.e4)/466)-3*y*m.sin((4*m.pi*x*m.e4)/466))                         )-42.35)                                                        )

x, y =  fsolve(equations, (1, 1))

print equations((x, y))

1197 3.5: wrong solution

Question:
Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included).

the correct solution should be
li = [1,2,3,4,5,6,7,8,9,10] evsqr = **list**(map(lambda x: x**2, filter(lambda x: x%2 == 0, li))) print(evsqr)

given solution
squaredNumbers = map(lambda x: x**2, range(1,21)) print squaredNumbers

Question 17 Unused import

On question 17 there is a import for the sys module, but, it seems to not be used on the code. Is that a mistake or does it makes some sense?

As far as I know, anything imported should be used.

How to make a tab open after payments is done

Hello
I request for assistance
I am new in python and I have a project with django.
How can someone create a tab which after payment of the desired thing it gets open
Example I cant view this house unless I make a payment.
When I make a payment the tab allows me to view the house
Kindly help

AttributeError: 'recta' object has no attribute 'ar

class recta():

def __init__(self,base,heig):
    self.base=base
    self.heig=heig  

def area(self):
    self.ar=self.base*self.heig
    
def __str__(self):
    return "the area of this rectangle is : "+(self.ar)

my_rect = recta(2,2)
print(my_rect)

This is the error message that I received:

AttributeError: 'recta' object has no attribute 'ar'

I will appreciate any help on this matter

question 20

the answer doesn't seem to be working properly.
"reverse() is not defined"

question 9: Using class

class Capital:
def init(self):
self.s=''
def line(self,a):
self.s=a
def printstr(self):
print(self.s.upper())

obj=Capital()
obj.line('''Hello World!
Let's party!''')
obj.printstr()

I have tried doing it using class keyword in python 3.7. Hope it's acceptable!

Tabs open after payments is done

Hello friend
I request for assistance
I am new in python and I have a project with django.
How can someone create a tab which after payment of the desired thing it gets open
Example I cant view this house unless I make a payment.
When I make a payment the tab allows me to view the house
Kindly help

Very small issue on #2

In the first sentence of the question:
"Write a program which can compute the factorial of a given numbers."
'numbers' should be singular.

error in sol.

can u please check solution of ques)20 , i found it erroneous.

No information in README

It is typically best practice to add information into the README so that users can know how to run the program and what it does. It doesn't have to be much but some steps on how to run python code would go a long way in improving the user experience.

code a python app will be used to make reservations to the restaurant

For this application first we have to identify the data that needs to be saved and accessed, with that we will churn out entities that will take form of classes and use inheritance in case of relationship. After that based on the use cases we can design functions and events flow.

so here if we see the requirement defined for application :

  1. There are customers who make reservation

  2. There are tables for which reservation are made.

  3. Waiters who will take orders.

  4. Food Item that will be added to bill

  5. Bill which has to be payed.

  6. Order which contain list of food items ordered with quantity

So five entities i.e. classes needs to be created.

Now, since customer and waiter are person so we can create an abstract class with some common attribute like name, ssn, phone number, address e.t.c. and then we can inherit it to make customer and waiter class with their specific attribute like waiter id for waiter and no. of accompaniment for customer.

Similarly food item can be an interface which can be inherited in veg and non veg abstract classes which can further inherited in different food items available in restaurant.

Now, for holding reservation details we need to create a reservation table in db which contains details like :

1.reservation id

2.table num

3.customer id

4.waiter id

5.date and time

6.order

7.bill

Now, below are the possible use cases that I can sort out :

  1. Make Reservation - For this use case from ui user will fill the details like time and no. of people for dinner reservation, based on that we will search in db for the availability of table with that capacity on that time. For this db query we can use table and reservation. If available, then we will send success response with table id to ui and then user can continue after filling his details like name, ssn e.t.c. and make reservation with confirmation button. With this we can generate a reservation num and save the details in that table with a waiter alloted to that.

  2. Waiter login - this is simple login flow so nothing new here.

  3. Waiter access to add order - Here at his home page waiter can select table (in case assigned to multiple table) for which he has to add order. Here on the ui we has to provide a search functionality

a) to search food items - so an event is made on click of search button which will call find query in food item db and return result. This result can be used by waiter and then click on add button after selecting quantity, we have

b) create an event to generate order or update order with those food item.

  1. Bill generation - When dinner is done then waiter can click on checkout button and then need to create an event which will create bill based on the order of that table and save it in database with waiter tip details :)

I have not created any class and function as based on programming language it changes but design will remain the same.

Now for error handling-

There can be multiple error as table not available, food item out of stock, total calculation at the time of bill generation and many other with technical errors like db query, logical errors.

Also , ui related errors like phone number not correct, ssn not provided e.t.c.

Alter Question 16

Question 16
Level 2

Legend |

*please fix |

Then, the output should be:
*1,9,25,49,81

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.

Solution:
values = raw_input()
*numbers = [int(x)**2 for x in values.split(",") if int(x)%2!=0]
print ",".join(numbers)
#----------------------------------------#

Question 3, Level-1

I am new to python and started working slowly with the example exercises.
I am getting following error on solution code below.
Solution code:

n = int(raw_input())
d = dict()
for i in range(1, n+1):
d[i] = i*i

print d

Here is the error:
TypeError: dict() takes exactly 1 argument (0 given)

It says we have to provide an argument inside the dict() (function).
please help to solve this.

graph plotting

plot a graph of live stock market using python 3 idle.

Unnecessary join step for "a comma-separated sequence on a single line"

For questions that require "a comma-separated sequence on a single line", many of the answers use a list to store solutions but then join the elements into a string. This is unnecessary, since a list is a comma-separated sequence that comes out on a single line (if your screen is big enough).

This is more just a wording issue.

Q1: Different solution

Mine solution is:

for i in range(2000, 3201):
    if i%7 == 0 and i%5 != 0:
        print(i, end = ', ')

Is there any particular reason why given solution with .append and .join is used, is it better then mine from some reason? Because the one I wrote takes less lines. I'm a complete beginner, apologize if my question is ridiculous.

Wrong solution on line 1953

Please write a program to generate a list with 5 random numbers between 100 and 200 inclusive.

The solution shown is
print(random.sample(range(100), 5))

However that will only generate numbers between 0 and 100, but the question asks for 100 to 200.

The solution should be
print(random.sample(range(100, 200), 5))

Q7: Different/shorter solution

X, Y = [int(num) for num in input("Enter numbers > ").split(',')]
arr = [[i*j for j in range(0, Y)] for i in range(0, X)]
print(arr)

Just been working through these questions (very useful btw) and came up with this as an alternative to the solution provided - which is better?

Question 2: Solution is wrong

It gives NameError: name 'raw_input' is not defined even when I add variable with raw_input.

This is my solution:

def numb_f(x):
    i = 1
    suma = 1
    while i < int(numb):
        suma =  suma * (i+1)
        i = i + 1
    return suma
numb = int(input("Please add a number: "))
if type(numb) == int:       
    print(numb_f(numb))
else:
    print("Please add number!")

Continuous loop for: Importing values from excel and assigning them to variables, solving equations and outputing the solution of the equations

Hello community,
I'm a mechanical engineer, and quite new to github. I'm doing research in Thinfilms. For my project, I have to take my experimental values which are in excel sheet format and use a python code to substitute these values in analytical equations, solve them and output the answer in a new excel column. This code should run on a continuous loop and automatically calculate solution for each input value (present in the column)

I'm a beginner in python and tried searching the web for answers, can someone please give me a hint as to how I can go about this?
Thanks

Line 1975 error

Hello,

The problem on line 1975 throws a syntax error. I am using python 3.6 and was wondering if the error is due to that or something else.

Thank You,

Separate questions from answers

Separating the answer in another file (answers.txt) could motivate people who want to practice without instantly checking the answer.

Question 16 output doesn't match description

Question 16 asks to "square each odd number in a list" when the given input and output don't match that statement, rather it only outputs the odd number not squared.

Small issue, but one nonetheless.

Question 5

Is the solution for question 5 correct?

I found it couldn't produce the expected output, did I miss anything?

Double reading file in python

hi

i have a file.txt with this content
file.txt
{
1
2
3
4
5
}

and i have file2.txt that there only a line of file.txt

file2.txt
{
3
}

now i want to replace content file2.txt with next line file.txt after compare

for exam:
first run
file2.txt > 4

second run
file2.txt > 5

third run
file2.txt > 1

but in third run file2.txt don't change...

this is my code

for line in file.readlines():
	if line == find_between(file2,'number" : "','",')+"\n":
		i = 1
		continue
	if i == 1:
		aaaaaa=string.replace(file2,find_between(file2,'number" : "','",'),line.rstrip('\n'))
		deleteContent(file2)
		file2.write(aaaaaa)
		print aaaaaa
		break

Q6: Shorter solution

import math
c,h=50,30
q=[str(int(round(math.sqrt((2cint(d))/h)))) for d in input().split(',')]
print(','.join(q))

This is a shorter and accurate solution. What do you think?

Tab opens ofter payment

Hello,
I request for assistance
I am new in python and I have a project with django.
How can someone create a tab which after payment of the desired thing it gets open
Example I cant view this house unless I make a payment.
When I make a payment the tab allows me to view the house
Kindly help

line 1087

the if in the loop maybe wrong?
tp=(1,2,3,4,5,6,7,8,9,10)
li=list()
for i in tp:
if i%2==0: #<-----tp[i] should be i
li.append(i)

tp2=tuple(li)
print (tp2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.