i know that 6/5 returns 1
and 6/5.0 returns 1.2
but suppose i am defining n=6 and d=5, i want n/d to return 1.2 instead of 1, how do i do it?
abhigyan91
0
Newbie Poster
Recommended Answers
Jump to PostTo answer your first question, set d = 5.0, OR, use
d/float(d) #float(n)/d works too
To answer your second question, it depends on what the code fragment is trying to do, and what your expected results are. I can launch into a long exposition on why I think it doesn't …
Jump to PostThat ought to work!
Not work maybe typeError.
'a' iterarte throught the list,then you have to compare'a ' == 'pear'
Now you compare l with 'pear'>>> l=['apple','orange','mango','pear','strawberry'] >>> l == 'pear' False >>>
l = ['apple','orange','mango','pear','strawberry'] for a in l: if(a …
Jump to PostReplying to your second question:
l=['apple','orange','mango','pear','strawberry'] for a in l: if(l=='pear'): l.remove(i)
That ought to work! :P
Why not simpply:
mylist = ['apple','orange','mango','pear','strawberry'] mylist.remove('pear') print(mylist) # ['apple', 'orange', 'mango', 'strawberry']
Jump to Posti know that 6/5 returns 1
and 6/5.0 returns 1.2
but suppose i am defining n=6 and d=5, i want n/d to return 1.2 instead of 1, how do i do it?With Python3 things have changed. Floating point division is now '/' and integer division '//'.
All 14 Replies
abhigyan91
0
Newbie Poster
scru
909
Posting Virtuoso
Featured Poster
sravan953
snippsat
661
Master Poster
sravan953
bumsfeld
413
Nearly a Posting Virtuoso
bumsfeld
413
Nearly a Posting Virtuoso
sravan953
sravan953
scru
909
Posting Virtuoso
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
abhigyan91
0
Newbie Poster
shadwickman
159
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.