1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jolli1 [7]
2 years ago
9

In Python write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs

the values of the list.
Ex: If the input is:

10
5
3
21
2
-6
the output is:

[10, 5, 3, 21, 2]

Code hints: while user_input >0: #This is the number that is greater than 0 from the list that is entered.

print(user_numbers) #Prints out the numbers greater than zero that are inputted at the top part.
Computers and Technology
1 answer:
Lilit [14]2 years ago
3 0

Answer:

ansList =input().split() #get input and split it by space

ansList = [int(i) for i in ansList if int(i)>0] #turn string to integer,and get all positive integers

print(ansList)

Explanation: I think this would work for you. I leace comments in the answer.

You might be interested in
Two files named numbers1.txt and numbers2.txt both have an unknown number of lines, each line consisting of a single positive in
Reika [66]

Answer:

see explaination for program code

Explanation:

scalar_product = 0

li=[]

li2=[]

#reading numbers1.txt and numbers2.txt intoli and li2 respectively

with open('numbers1.txt') as n1, open('numbers2.txt') as n2:

for line1 in n1:

li.append(int(line1))

for line2 in n2:

li2.append(int(line2))

#storing min list size into variable l

a=len(li)

b=len(li2)

if a<b:

l=a

else:

l=b

#calculating scalar product

for i in range(l):

scalar_product=scalar_product+li[i]*li2[i]

print("scalar product is",scalar_product)

6 0
4 years ago
Python
andreyandreev [35.5K]

Answer:

<h2>1)   </h2>

h = 19  # h is already assigned a positive integer value 19

i = 1  # used to calculate perfect square

q = 0   # stores the sum of the perfect squares

while q < h:  

# this loop executes until value of number of perfect squares is less than h

   q = q + (i*i)  # to calculate the sum of perfect squares

   i = i + 1  # increments i by 1 at every iteration

print(q) # displays the sum of perfect squares

Output:

30

Explanation:

Here we see that the sum of the perfect square is printed in the output i.e. 30. If we want to assign value 4 to q then we should alter the code as  following:  

h = 19

i = 1

sum_of_ps = 0

q=0

while sum_of_ps < h:

   sum_of_ps = sum_of_ps + (i*i)

   q = q + 1

   i = i + 1  

print(q)  

If you want to take input from the user and also display the perfect squares in output you can use the following code:

h = int(input('Enter the value of h: ')) #takes value of h from user

i = 1

sum_of_ps = 0

q=0

while sum_of_ps < h:

   sum_of_ps = sum_of_ps + (i*i)

   print(i*i) #displays the perfect squares of h

   q = q + 1

   i = i + 1    

print(sum_of_ps)   #displays sum of perfect squares

print(q) #displays number of perfect squares whose value is less than h

Output:

1

4

9

16

30

4

<h2>2)</h2>

# k and m are already assigned positive integers 10 and 40

k = 10  

m = 40  

i = 1  # i is initialized to 1

q = 0  # q stores the number of perfect squares between k and m

while i*i < m:  # loop computes perfect square of numbers between k and m

   if i*i > k:          

       q = q + 1  # counts the number of perfect squares

   i = i + 1  #increments the value of i at each iteration

print (q) # prints the no of perfect squares between k and m

If you want to display the perfect squares too use , add print(i*i) statement after if statement  if i*i > k:        

Output:

3

<h2>3)</h2>

def Fibonacci(n):  # method Fibonacci which has an integer parameter n

   if n <= 1:  # if the value of n is less than or equals to 1

       result = n  # stores the value of n into result

   elif n > 1:  # else if the value of n is greater than 1

       result = Fibonacci(n-1) + Fibonacci(n-2)  

# calls Fibonacci method recursively to associate nth value of Fibonacci #sequence with variable result

   return result     #returns the final value stored in result variable

print(Fibonacci(8))

#calls Fibonacci function and passes value 8 to it

Output:

21

8 0
3 years ago
A friend of Alex has gifted a movie collection, and Alex is excited to watch them all as quickly as possible. The duration of th
marishachu [46]

To find out the duration of alex's movies, you can use the code in C++ to make this calculation, where you will only need the number of movies and their duration, as well:

<h3>Writing code in C++:</h3>

<em>#include<bits/stdc++.h></em>

<em>using namespace std;</em>

<em>struct Movie {</em>

<em>   int timeBegin, duration, timeEnd;</em>

<em>   bool operator<(const Movie& another) const {</em>

<em>      return timeEnd < another.timeEnd;</em>

<em>   }</em>

<em>};</em>

<em>struct Festival {</em>

<em>   int count;</em>

<em>   vector<Movie> movies;</em>

<em>};</em>

<em>Festival* initialize(int timeBegin[], int duration[], int count) {</em>

<em>   Festival* filmFestival = new Festival;</em>

<em>   filmFestival->count = count;</em>

<em>   for (int i = 0; i < count; i++) {</em>

<em>      Movie temp;</em>

<em>      temp.timeBegin = timeBegin[i];</em>

<em>      temp.duration = duration[i];</em>

<em>      temp.timeEnd = timeBegin[i] + duration[i];</em>

<em>      filmFestival->movies.push_back(temp);</em>

<em>   }</em>

<em>   return filmFestival;</em>

<em>}</em>

<em>int solve(Festival* fest) {</em>

<em>   int res = 0;</em>

<em>   sort(fest->movies.begin(), fest->movies.end());</em>

<em>   int timeEnd = -1;</em>

<em>   for (int i = 0; i < fest->count; i++) {</em>

<em>      if (fest->movies[i].timeBegin >= timeEnd) {</em>

<em>         res++;</em>

<em>            timeEnd = fest->movies[i].timeEnd;</em>

<em>      }</em>

<em>   }</em>

<em>   return res;</em>

<em>}</em>

<em>int main(int argc, char *argv[]) {</em>

<em>int timeBegin[] = {1, 3, 0, 5, 5, 8, 8};</em>

<em>int duration[] = {3, 2, 2, 4, 3, 2, 3};</em>

<em>Festival * fest;</em>

<em>fest = initialize(timeBegin,duration, 7);</em>

<em>cout << solve(fest) << endl;</em>

<em>return 0;</em>

<em>}</em>

See more about C Code at brainly.com/question/17544466

#SPJ1

8 0
2 years ago
Write Java program to allow the user to input the amount of deposit, yearly interest rate (percentage), and income tax(percentag
Vedmedyk [2.9K]

Answer:

import java.util.Scanner;

public class num12 {

   public static void main(String[] args) {

       Scanner scr = new Scanner(System.in);

       System.out.println("Enter a Deposit Amount");

       double amt = scr.nextDouble();

       System.out.println("Income tax in percentage");

       double incomeTaxRate = scr.nextDouble()/100;

       System.out.println("Yearly interest rate:");

       double rate = scr.nextDouble();

       double intRate = rate/100;

       double interest = (amt*intRate)-(amt*incomeTaxRate);

       System.out.println("The Interest on "+amt+" at "+rate+"% after one year is "+interest);

   }

}

Explanation:

Find the sample output attached

Java's Scanner class is used to prompt and receive values for deposit amount, income tax rate and interest rate

The yearly interest is calculate by interest = (amt*intRate)-(amt*incomeTaxRate);

3 0
3 years ago
M/J Business Keyboarding Guided Notes Module 2
attashe74 [19]
Why is there so much
8 0
3 years ago
Other questions:
  • How do I delete a class on Edulastic?
    8·2 answers
  • Nina wants to create a digital backup of her holiday videos to view later. What two of these devices could she use?
    11·2 answers
  • List six parts of a computer system and which are output and which is an input device
    5·1 answer
  • Give two examples of html structure
    15·1 answer
  • You are network administrator for an Active Directory forest with a single domain. Then network has three sites with one domain
    12·1 answer
  • Write a Python function that join the two string and print it ​
    14·2 answers
  • Consider the following code segment.
    10·1 answer
  • Can someone tell me what this means Higfaa
    6·1 answer
  • I need subscribers plz ​
    15·2 answers
  • Your son is complaining that his smartphone is broken. He tells you that he cannot connect to the internet, nor can he make or r
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!