Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: Why do these codes give different answers?
Post: RE: Why do these codes give different answers?
(Dec-14-2020, 10:21 AM)DeaD_EyE Wrote: for char in "Robert":
print(char)Output:R
o
b
e
r
tThe first element is the str R. What do you think will happen, if you return True?f
Allright ! I've got ... |
|
pooyan89 |
Homework |
5 |
2,484 |
Dec-14-2020, 11:43 AM |
|
|
Thread: Why do these codes give different answers?
Post: RE: Why do these codes give different answers?
(Dec-14-2020, 10:21 AM)DeaD_EyE Wrote: for char in "Robert":
print(char)Output:R
o
b
e
r
tI thought it would loop through all the words in there.
The first element is the str R. What do you thi... |
|
pooyan89 |
Homework |
5 |
2,484 |
Dec-14-2020, 11:33 AM |
|
|
Thread: Why do these codes give different answers?
Post: Why do these codes give different answers?
My goal is to write a function that takes a letter as an argument, it loops through its words and gives me False if it contains 'e' otherwise it is True.
The correct code is:
def has_no_e(letter):
... |
|
pooyan89 |
Homework |
5 |
2,484 |
Dec-14-2020, 09:49 AM |
|
|
Thread: If the argument is not int then make it int!
Post: If the argument is not int then make it int!
Hi !
I have to write a function named Countdown:
def countdown(n):
while n > 0:
print(n)
n = n - 1
print('Blastoff!')Now if I enter a non-integer value and I want Python to... |
|
pooyan89 |
Homework |
2 |
1,625 |
Dec-11-2020, 02:25 PM |
|
|
Thread: Algebric equation with Sympy
Post: RE: Algebric equation with Sympy
(Jul-16-2019, 10:48 PM)scidam Wrote: You are likely need to declare your equations (using Eq), e.g.
eq1 = Eq(((4.13 + I ... )
eq2 = Eq(((570*s + ... )and, finally, solve it, as you did:
solution ... |
|
pooyan89 |
Homework |
3 |
1,954 |
Jul-17-2019, 03:49 PM |
|
|
Thread: Algebric equation with Sympy
Post: Algebric equation with Sympy
Hi !
I have two hard equations which I tried to solve them with a numerical value by using Sympy:
from sympy import *
import sympy as sy
import math
s,v=symbols('s v')
s=((4.13 + I*568)/(4*(s+v))... |
|
pooyan89 |
Homework |
3 |
1,954 |
Jul-16-2019, 07:29 PM |
|
|
Thread: A function that checks if the list is sorted
Post: RE: A function that checks if the list is sorted
(Jun-16-2019, 05:42 PM)noisefloor Wrote: Hi,
@ppoyan89: iterating over an iterable with for x in range(len(iterable)) is still a bad anti-pattern. Don't you have any motivation to use what you lear... |
|
pooyan89 |
Homework |
16 |
16,517 |
Jun-16-2019, 05:52 PM |
|
|
Thread: A function that checks if the list is sorted
Post: RE: A function that checks if the list is sorted
(Jun-16-2019, 05:28 PM)Yoriz Wrote: It wont, your code says as soon as it finds a[i]<=a[i+1] return True
So I see if I write:
def is_sorted(l):
for i in range(len(l)-1):
print(l[i],l... |
|
pooyan89 |
Homework |
16 |
16,517 |
Jun-16-2019, 05:34 PM |
|
|
Thread: A function that checks if the list is sorted
Post: RE: A function that checks if the list is sorted
(Jun-16-2019, 05:21 PM)Yoriz Wrote: The first check for comparison it does is, 1 is equal to or less than 2 which is true so it stops.
But doesn't it go through the whole loop? |
|
pooyan89 |
Homework |
16 |
16,517 |
Jun-16-2019, 05:24 PM |
|
|
Thread: A function that checks if the list is sorted
Post: A function that checks if the list is sorted
The task is :
Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise. For example:
>>> is_sorted([... |
|
pooyan89 |
Homework |
16 |
16,517 |
Jun-16-2019, 05:14 PM |
|
|
Thread: Duplicated words in a list
Post: RE: Duplicated words in a list
(Jun-15-2019, 01:24 PM)Yoriz Wrote: If you add a print you'll see the following
when the first loop is on the second item 'bar', the second loop is also calls the second item.
when the first loop is... |
|
pooyan89 |
Homework |
7 |
9,287 |
Jun-15-2019, 01:27 PM |
|
|
Thread: Duplicated words in a list
Post: RE: Duplicated words in a list
(Jun-15-2019, 12:57 PM)ThomasL Wrote: Think simpler!
def has_duplicates(source):
return len(set(source)) != len(source)
thank you but I have to solve it with loops, I wanna know why this code do... |
|
pooyan89 |
Homework |
7 |
9,287 |
Jun-15-2019, 12:59 PM |
|
|
Thread: Duplicated words in a list
Post: Duplicated words in a list
Hi!
I have a task:
Write a function called has_duplicates that takes a list and returns True if there is any element that appears more than once. It should not modify the original list.
Here is my ... |
|
pooyan89 |
Homework |
7 |
9,287 |
Jun-15-2019, 12:47 PM |
|
|
Thread: A function that takes a word and a string of forbidden letters
Post: RE: A function that takes a word and a string of f...
(Jun-12-2019, 07:23 PM)Yoriz Wrote: In the first case it is checking if w is in 'o' which it is not so it doesn't return False,
moves on the the next letter in the loop, o is in 'o' so returns False... |
|
pooyan89 |
Homework |
5 |
4,660 |
Jun-12-2019, 07:26 PM |
|
|
Thread: A function that takes a word and a string of forbidden letters
Post: RE: A function that takes a word and a string of f...
(Jun-12-2019, 07:12 PM)Yoriz Wrote: The loop stops straight away because w is not in 'o' so it returns True.
But it is not so in the first case. Can you explain more ?! |
|
pooyan89 |
Homework |
5 |
4,660 |
Jun-12-2019, 07:18 PM |
|
|
Thread: A function that takes a word and a string of forbidden letters
Post: A function that takes a word and a string of forbi...
Hi I have a question:
Write a function named avoids that takes a word and a string of forbidden letters, and that returns True if the word doesn’t use any of the forbidden letters.
The solution is :
... |
|
pooyan89 |
Homework |
5 |
4,660 |
Jun-12-2019, 07:04 PM |