[SOLVED] COM1001 Lab 2

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product

Write    a   Python program  which   takes   a   set   of     inputs   that        contain strings, positive   integers      and        9loating  point  numbers     in   mixed   order,   prints    the sum       of    the integers,    sum       of          the   9loats   and        concatenation  of  the strings  in            separate              lines      in            this        order.

Speci&ication details:              

  • There is             no           speci9ic               order    in            the         given
  • Input may not         provide                any        integers,              or           9loats   or           Your      program            should  not         print      any        value     if             an           item      of            that        type       is             not            provided.            For         example,             if             no           int          item      is             provided,            then       print            no           value     for          integers.              Similar for          9loats   and        strings..Please   look       at            the            sample outputs                if             it             is             not         clear.

Constraints:

  • You are not allowed to use any string class func3ons, such as isnumeric() or str.isdigit() etc. You need to iden3fy the type of the items by inspec3ng individual characters in it (see the Hint below)
  • Floa3ng point numbers will only be provided using dot (.) conven3on; and dot (.) will only appear in float numbers, i.e. strings will not contain any dots.

Hints:

You will read the input using:

               inputs = map(str, input().split())

ADer reading, inputs variable is bound to a sequence (list) of strings. You can iterate over the individual items using in operator in a for loop, i.e. similar to itera3ng over a range of values using the range func3on; e.g. for item in inputs:.

You are expected to implement your own solu3ons to determine if a par3cular string contains an integer or a float number using itera3ons over the characters in the string. As we have seen, you can iterate over individual characters of a string, str, using in operator; e.g. for chr in str:

I/O Format:

Input format: [[posi3ve integer]*[Space][float]*[Space][string]*[Space]]*

Output

format:<sum_of_ints_if_given>[Newline]<sum_of_floats_if_given>[Newline]<concat_of_strings_if_gi ven>[Newline]

Note that:

  • Sample input and output files are provided.
  • [x]* means, zero or more elements of x
Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.